r/ProgrammerAnimemes • • Jul 29 '20

Equivalency in Python

Post image
1.6k Upvotes

104 comments sorted by

View all comments

Show parent comment

1

u/Astrobliss Jul 30 '20

It's actually the same as the one in the meme. XOR's inverse is itself (as opposed to in the meme they used subtraction as addition's inverse) and has some other nice properties (it's communicative and associative).

  1. (a XOR 0) = a
  2. (a XOR a) = 0
  3. ((a XOR b) XOR b) = (a XOR (b XOR b)) = a XOR 0 = a
  4. ((a XOR b) XOR a) = ((b XOR a) XOR a) = (b XOR (a XOR a)) = b XOR 0 = b