In [49]:
x = 0x05 #00000111
# Print in Hex and Binary
print ("x = 0x{0:x}".format(x))
print ("x = b\'{0:b}'".format(x))
# Create bitmask with bit 4 enabled
y = 1 << 4
print ("y = b\'{0:b}'".format(y))
# Turn on bit 4 of x
z = x | y
print ("z = x | y = b\'{0:b}'".format(z))
# Turn off z bit 4
w = z ^ y
print ("z ^ y = b\'{0:b}'".format(w))
# Multiply x by 2
print ("2*{} = {}".format(x, x << 1))
In [ ]: