Python bitwise AND is done with the &
operator.
>>> 38 & 51
34
The way it works is that it will do an AND operation at the bit level. Each bit of the 32 bit integer is compared with the bit in the same position on the other 32 bit integer. If both bits are 1, the result will be a 1, otherwise the result is a 0. So in the above example:
38 = 00000000 00000000 00000000 00100110
51 = 00000000 00000000 00000000 00110011
= 00000000 00000000 00000000 00100010 = 34
Bitwise AND can only be done with integers
>>> 3.2 & 5.5
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for &: 'float' and 'float'