Python Bitwise XOR

Python bitwise XOR is done with the ^ operator.

>>> 38 ^ 51
21

The way it works is that it will do a XOR 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. XOR will output a 1 if the bits do not match. So in the above example:

38 = 00000000 00000000 00000000 00100110
51 = 00000000 00000000 00000000 00110011
   = 00000000 00000000 00000000 00010101 = 21

Bitwise XOR 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'