What is bitwise operator in Python
In this article, we will learn about bitwise operators.
Bitwise operators are those operators which perform bitwise operations on numbers. The bitwise operators in Python first convert the decimal number into binary and perform operations bit-by-bit and finally returns the output in decimal form.
BITWISE OPERATORS IN PYTHON
Bitwise AND – &
Bitwise OR – |
Bitwise NOT – ~
Bitwise XOR – ^
Bitwise LEFT SHIFT – <<
Bitwise RIGHT SHIFT – >>
a = 22 b = 11 # bitwise and print(a & b) # bitwise or print(a | b) # bitwise not print(~a) # bitwise xor print(a ^ b) # left shift. # shift by 1 position print(a<<1) # right shift # shift by 2 position print(a>>1)
Output:
2 31 -23 29 44 11
Subscribe
Login
Please login to comment
0 Discussion