aboutsummaryrefslogtreecommitdiffstats
path: root/mevent.c
blob: 4fd176a3ab58e33ffb0af53124404ddd5618b45c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <stdio.h>
#include <stdlib.h>

#define B2BP "%d%d%d%d%d%d%d%d"
#define B2B(byte)  \
    (byte & 0x80 ? 1 : 0), \
    (byte & 0x40 ? 1 : 0), \
    (byte & 0x20 ? 1 : 0), \
    (byte & 0x10 ? 1 : 0), \
    (byte & 0x08 ? 1 : 0), \
    (byte & 0x04 ? 1 : 0), \
    (byte & 0x02 ? 1 : 0), \
    (byte & 0x01 ? 1 : 0)

int main(int argc, char **argv)
{
    signed char *c=malloc(3*sizeof(char)), i;
    while(1){
        for(i=0; i<3; i++)
            c[i] = getchar();
        printf("%2x %2x %2x ", (unsigned char)c[0], (unsigned char)c[1], (unsigned char)c[2]);
        printf(": "B2BP B2BP B2BP" ", B2B(c[0]), B2B(c[1]), B2B(c[2]));
        printf(": %d %d %d\n", (signed char)c[0], (signed char)c[1], (signed char)c[2]);
    }
    return 0;
}