Odd behavior of the Python.xor operator

I am working on an encryption puzzle, and I need to take exclusive or two binary numbers (I use the package operatorin Python). If I run operator.xor(1001111, 1100001), for example, I get very strange output 2068086. Why doesn't he return, 0101110or at least 101110?

+4
source share
3 answers

Since Python does not see this as binary numbers. Use instead:

operator.xor(0b1001111, 0b1100001)
+9
source

The calculated answer uses the decimal values ​​you provided, not their binary form. What you are really asking is ...

1001111 ^ 1100001

79 ^ 97. ...

0b1001111 ^ 0b1100001

Python? .

+7

1001111 1100001 . 1001111 , , , 1100001 - , . Python . 0b Python/Python 3. , :

operator.xor(0b1001111, 0b1100001)

! 46 . . , Python/Python 3. bin(n). , 0b. , :

bin(operator.xor(0b1001111, 0b1100001))

0b ( , ), [2:] :

bin(operator.xor(0b1001111, 0b1100001))[2:]

( , * )
, operator.xor() :)
(99,9%), a^b. , , xor? xor, operator : from operator import a, b.... : bin(xor(a,b)). , , , :)

0

Source: https://habr.com/ru/post/1623480/


All Articles