-
Notifications
You must be signed in to change notification settings - Fork 0
/
aa.c
45 lines (44 loc) · 1016 Bytes
/
aa.c
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
int a;
int i = 0;
char *p;
if( argc != 2 )
{
printf("usage: %s <number>\n", argv[0]);
}
else if (!strcmp(argv[1], "0"))
{
printf("00000000\t0x0\t00\n");
} else
{
if(0 < (a = atoi(argv[1])))
{ for (i = 8*sizeof(char)-1; i >= 0; --i)
{
if ((a >> i) & 0x01)
putchar('1');
else
putchar('0');
}
printf("\t0x%x\t0%o", a, a);
}
else
{
p = argv[1];
while(*p)
{
a = *p++;
for (i = 8*sizeof(char)-1; i >= 0; --i)
{
if ((a >> i) & 0x01) putchar('1');
else putchar('0');
}
printf("\t0x%x\t0%o", a, a);
putchar('\n');
}
}
putchar('\n');
}
}