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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
#include <stdio.h>
main(argc,argv)
int argc;
char *argv[];
{
int f,l,r;
unsigned int c;
char *binary();
if(argc==1)
{
printf("%s: usage %s string1 [..stringn] | -c num1 [.. num n]\n",
argv[0],argv[0]);
exit(-1);
}
if(strcmp(argv[1],"-c"))
{
for(r=1;r<argc;r++)
{
l=strlen(argv[r]);
for(f=0;f<l;f++)
{
c=(unsigned int)*(argv[r]+f);
printf("%c (%3d - 0x%2.2X %%%s)\n",
((*(argv[r]+f) > 31) ? (*(argv[r]+f)) : '?')
,c,c,binary(c,8));
}
}
}
else
{
if(argc==2)
{
printf("%s:usage %s -c num1 [.. num n]\n",argv[0],argv[0]);
exit(-1);
}
for(f=2;f<argc;f++)
{
c=(char)strtol(argv[f],NULL,0);
printf("%c (%3d - 0x%2.2X %%%s)\n",
(c>31) ? (char)c : '?',
c,c,binary(c,8));
}
}
}
char *binary(i,w)
unsigned int i,w;
{
static char buff[1024],*p;
unsigned int c=w,b=1<<(w-1);
p=buff;
for(;c--;b=b>>1)
if(i&b)
*p++='1';
else
*p++='0';
*p='\0';
return(buff);
}
|