Just thought somebody might find it interesting.
a = 0b11101110
- define a function for flipping bits
find the length of the variable you want to flip
length = len(bin(x))-2
the mask, a string for now
mask = "0b"
add +1 to your mask until it has enough of them to flip the variable
for i in range(length):
mask += "1"
turn your mask into a intreger with a base of 2 by using the int function
mask = int(mask, 2)
desired = a ^ mask
print the binary string
call our variable