-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbitwise.c
More file actions
54 lines (42 loc) · 675 Bytes
/
Copy pathbitwise.c
File metadata and controls
54 lines (42 loc) · 675 Bytes
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
#include <stdio.h>
int main()
{
int index;
unsigned char bitmask;
unsigned char c0, c1, c2, c3;
c0 = 8;
c0 = 0x8;
// Assign binary value
c0 = 0b1000;
printf("%u\n", c0);
c0 = '0';
// print bit map
bitmask = 1 << (8*sizeof(c0) - 1);
while (bitmask)
{
printf("%d ", (bitmask & c0)? 1 : 0);
bitmask = bitmask >> 1;
}
printf("\n");
// or |
c0 = 2;
c1 = 4;
c0 = 0b00000010;
c1 = 0b00000100;
c2 = c0 | c1;
printf("or %u\n", c2);
// and &
c0 = 2;
c1 = 6;
c0 = 0b00000010;
c1 = 0b00000110;
c2 = c0 & c1;
printf("and %u\n", c2);
// xor ^
c0 = 2;
c1 = 6;
c0 = 0b00000010;
c1 = 0b00000110;
c2 = c0 ^ c1;
printf("and %u\n", c2);
}