I am working on an encryption puzzle and am needing to take the exclusive or of two binary numbers (I'm using the operator
package in Python). If I run operator.xor(1001111, 1100001)
for instance I get the very weird output 2068086
. Why doesn't it return 0101110
or at least 101110
?
Because Python doesn't see that as binary numbers. Instead use:
operator.xor(0b1001111, 0b1100001)
The calculated answer is using the decimal values you provided, not their binary appearance. What you are really asking is...
1001111 ^ 1100001
When you mean is 79 ^ 97
. Instead try using the binary literals as so...
0b1001111 ^ 0b1100001
See How do you express binary literals in Python? for more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With