In order to test building an Xor operation with more basic building blocks (using Nand, Or, and And in my case) I need to be able to do a Not operation. The built-in n
n
The general form given by John La Rooy, can be simplified in this way (python == 2.7 and >=3.1):
def bit_not(n): return (1 << n.bit_length()) - 1 - n