I have the following problem with the xor operator (^) in python. I have two binary numbers, let a = 10100111 and b = 10000000. When I use the xor operator,
print (10000000 ^ 10100111)
I get the result of 166671 instead of 00100111. However, when I use
print (100 ^ 101)
I get the appropriate result in binary of 1 (001). Even if I use
print int(a) ^ int(b)
I still get the result of 166671.
Questions:
Why do I get the result of 166671 instead of the binary result of 00100111?
Why do I get the appropriate result when I use 100^101?
I am running Python version 2.7.2.
010isn't either 10 (read in decimal) or 2 (read in binary), it's 8. The0prefix, without ab, means "read this number as octal, i.e. base 8". Just a heads-up.