-
Notifications
You must be signed in to change notification settings - Fork 0
/
toBin.c
87 lines (77 loc) · 2.6 KB
/
toBin.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
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <stdlib.h>
#include <stdio.h>
#include <byteswap.h>
struct b_field {
#ifdef VXWORKS
unsigned b_31: 1; unsigned b_30: 1;
unsigned b_29: 1; unsigned b_28: 1;
unsigned b_27: 1; unsigned b_26: 1;
unsigned b_25: 1; unsigned b_24: 1;
unsigned b_23: 1; unsigned b_22: 1;
unsigned b_21: 1; unsigned b_20: 1;
unsigned b_19: 1; unsigned b_18: 1;
unsigned b_17: 1; unsigned b_16: 1;
unsigned b_15: 1; unsigned b_14: 1;
unsigned b_13: 1; unsigned b_12: 1;
unsigned b_11: 1; unsigned b_10: 1;
unsigned b_9: 1; unsigned b_8: 1;
unsigned b_7: 1; unsigned b_6: 1;
unsigned b_5: 1; unsigned b_4: 1;
unsigned b_3: 1; unsigned b_2: 1;
unsigned b_1: 1; unsigned b_0: 1;
#else
unsigned b_0 : 1; unsigned b_1 : 1; unsigned b_2 : 1; unsigned b_3 : 1;
unsigned b_4 : 1; unsigned b_5 : 1; unsigned b_6 : 1; unsigned b_7 : 1;
unsigned b_8 : 1; unsigned b_9 : 1; unsigned b_10: 1; unsigned b_11: 1;
unsigned b_12: 1; unsigned b_13: 1; unsigned b_14: 1; unsigned b_15: 1;
unsigned b_16: 1; unsigned b_17: 1; unsigned b_18: 1; unsigned b_19: 1;
unsigned b_20: 1; unsigned b_21: 1; unsigned b_22: 1; unsigned b_23: 1;
unsigned b_24: 1; unsigned b_25: 1; unsigned b_26: 1; unsigned b_27: 1;
unsigned b_28: 1; unsigned b_29: 1; unsigned b_30: 1; unsigned b_31: 1;
#endif
};
void print_bit( struct b_field *bit );
void print_hex(unsigned int ihex);
int
main(int argc, char **argv)
{
unsigned int input=0;
struct b_field *bit;
if(argc==2)
{
input = (unsigned int) strtoll(argv[1],NULL,16);
}
else
return 0;
print_bit( (struct b_field *)&input);
print_hex(input);
}
void
print_bit( struct b_field *bit )
{
printf("\n 28 24 20 16 12 8 4 0\n");
printf("0x%08X: ",*bit);
printf("%d%d%d%d %d%d%d%d %d%d%d%d %d%d%d%d %d%d%d%d %d%d%d%d %d%d%d%d %d%d%d%d\n",
bit->b_31,bit->b_30,bit->b_29,bit->b_28,
bit->b_27,bit->b_26,bit->b_25,bit->b_24,
bit->b_23,bit->b_22,bit->b_21,bit->b_20,
bit->b_19,bit->b_18,bit->b_17,bit->b_16,
bit->b_15,bit->b_14,bit->b_13,bit->b_12,
bit->b_11,bit->b_10,bit->b_9,bit->b_8,
bit->b_7,bit->b_6,bit->b_5,bit->b_4,
bit->b_3,bit->b_2,bit->b_1,bit->b_0 );
}
void
print_hex(unsigned int ihex)
{
printf(" 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X",
((ihex)&0xF0000000)>>28,
((ihex)&0x0F000000)>>24,
((ihex)&0x00F00000)>>20,
((ihex)&0x000F0000)>>16,
((ihex)&0x0000F000)>>12,
((ihex)&0x00000F00)>>8,
((ihex)&0x000000F0)>>4,
((ihex)&0x0000000F)>>0);
printf("\n\n");
}