Python Program To Demonstrate Bitwise Operators
Write Python code to demonstrate bitwise operators
# WAP to demonstrate the use of bitwise operators. a = 7 b = 5 print("Bitwise AND : 7 & 5 =", a & b) print("Bitwise OR : 7 | 5 =", a | b) print("Bitwise XOR : 7 ^ 5 =0", a ^ b) print("Bitwise COMPLEMENT : ~7 =", ~a) print("Right shift : 7 >> 2 =", a >> 2) print("Left shift : 7 << 2 =", a << 2)
Output:
Bitwise AND : 7 & 5 = 5
Bitwise OR : 7 | 5 = 7
Bitwise XOR : 7 ^ 5 =0 2
Bitwise COMPLEMENT : ~7 = -8
Right shift : 7 >> 2 = 1
Left shift : 7 << 2 = 28