The AND bitwise operator can be used to mask bits off. We often use the AND bitwise operation to mask off some bits, as a 0 in a certain bit position will make the result ‘0’, while a ‘1’ at this position will preserve the value of the bit. For example if we wish to mask bit 3 we can use:
if ((val & 0x08) == 0x08) print "Bit 3 is set to a 1"