-
Notifications
You must be signed in to change notification settings - Fork 0
/
bin.c
36 lines (35 loc) · 857 Bytes
/
bin.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
void to_bin(byte b) {
int binary[8];
for (int n = 0; n < 8; n++)
{
/*
bit a bit b a & b (a AND b)
0 & 0 = 0
0 & 1 = 0
1 & 0 = 0
1 & 1 = 1
>> 0
0100 1100 - 76 & 0000 0001 = 0000 0000
>> 1
0010 0110 - 38 & 0000 0001 = 0000 0000
>> 2
0001 0011 - 19 & 0000 0001 = 0000 0001
>> 3
0000 1001 - 9 & 0000 0001 = 0000 0001
>> 4
0000 0100 - 4 & 0000 0001 = 0000 0000
>> 5
0000 0010 - 2 & 0000 0001 = 0000 0000
>> 6
0000 0001 - 1 & 0000 0001 = 0000 0001
>> 7
0000 0000 - 0 & 0000 0001 = 0000 0000
*/
binary[7 - n] = (b >> n) & 1;
}
// for (int n = 0; n < 8; n++)
// {
// printf("%d", binary[n]);
// }
// printf("\n");
}