# Bitwise Operation in python

```a = 5
b = 4
or_operation_way_1 = a or b
or_operation_way_2 = a | b
print("After bitwise or operation",or_operation_way_1)
print()
print("After bitwise or operation",or_operation_way_2)
'''

a --&gt; 0 0 0 0 0 1 0 1
b --&gt; 0 0 0 0 0 1 0 0
-------------------------
a or b  --&gt; 0 0 0 0 0 1 0 1
'''

and_operation_way_1 = a &amp; b
and_operation_way_2 = a and b
print()
print("After bitwise and operation",and_operation_way_1)
print()
print("After bitwise and operation",and_operation_way_2)

'''
a --&gt; 0 0 0 0 0 1 0 1
b --&gt; 0 0 0 0 0 1 0 0
-------------------------
a and b  --&gt; 0 0 0 0 0 1 0 0
'''
xor_operation = a ^ b
print()
print("After bitwise xor operation", xor_operation)
'''
a --&gt; 0 0 0 0 0 1 0 1
b --&gt; 0 0 0 0 0 1 0 0
-------------------------
a xor b  --&gt; 0 0 0 0 0 0 0 1
'''
leftshift_operation = a &lt;&lt; 1
print()
print("After left shift operation, shifting by one bit",
leftshift_operation)
'''
a --&gt; 0 0 0 0 0 1 0 1
&lt;--------------------
a --&gt; 0 0 0 0 1 0 1 0

'''

rightshift_operation = a &gt;&gt; 1
print()
print("After right shift operation,shifting by one bit",rightshift_operation)

'''
a --&gt; 0 0 0 0 0 1 0 1
--------------------&gt;
a --&gt; 0 0 0 0 0 0 1 0
'''

c = 5
print("After Bitwise NOT operation",~c)```
``````Output:-

After bitwise or operation 5

After bitwise or operation 5

After bitwise and operation 4

After bitwise and operation 4

After bitwise xor operation 1

After left shift operation, shifting by one bit 10

After right shift operation,shifting by one bit 2
After Bitwise NOT operation -6``````

Note:- Tripple single quotes are used to comment multiple lines in python.

Contributed by – Devanshu Kumar