Repository navigation
Expand file tree
/
Copy pathBitwise Operators.txt
More file actions
64 lines (55 loc) · 1.7 KB
/
Copy pathBitwise Operators.txt
File metadata and controls
64 lines (55 loc) · 1.7 KB
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
Bitwise operators--> used to compare binary numbers bitwise
--> AND &
--> OR |
--> NOT ~
--> XOR ^
--> Left shift <<
--> Right shift >>
Binary--> 0 or 1
4-bit--> 0000=0
1111=15
Positionl values--> 2^3 2^2 2^1 2^0 Decimal
8 4 2 1
0 0 0 0 0
0 0 0 1 1
0 0 1 0 2
0 0 1 1 3
0 1 0 0 4
0 1 0 1 5
0 1 1 0 6
0 1 1 1 7
1 0 0 0 8
1 0 0 1 9
1 0 1 0 10
1 0 1 1 11
1 1 0 0 12
1 1 0 1 13
1 1 1 0 14
1 1 1 1 15
--> (2^3*0)+(2^2*1)+(2^1*0)+(2^0*1)=5
8*0 + 4*1 + 2*0 + 1*1
4 + 1 = 5
AND &--> True if both the bits are true
0 & 0 = 0
0 & 1 = 0
1 & 0 = 0
1 & 1 = 1
OR |--> True if any one of the bits is true
0 & 0 = 0
0 & 1 = 1
1 & 0 = 1
1 & 1 = 1
XOR ^--> True if only one bit is true
0 & 0 = 0
0 & 1 = 1
1 & 0 = 1
1 & 1 = 0 0000 & 1010 =
NOT~ --> Reverses the bits
~0=1 ~1=0
~0000 --> 1111
Left shift(<<) Right shift(>>)
1= 0001 4=0100
0001<<2 0100>>2
0010=2 0010=2
0100=4 0001=1
1001