int type bit operation
Bit calculation
shift left
x = 1 # 0001
x << 2 # shift left 2 bits: 0100
print x
The code above generates the following result.
Bitwise or
x = 1 # 0001
x | 2 # bitwise OR: 0011
print x
The code above generates the following result.
bitwise AND
x = 1 # 0001
x & 1 # bitwise AND: 0001
print x
The code above generates the following result.