minus-squaredmadtoPython•[Meme] Swapping integers in Pythonlinkfedilinkarrow-up5·edit-22 years agoxor has the property x ^ x = 0, and x ^ 0 = x. So, x ^ x ^ y = y a' = a ^ b b' = b ^ a' = b ^ (a ^ b) = a a'' = (a ^ b) ^ a = b This is pretty clever, I’ve never seen this for a swap. linkfedilink
xor has the property x ^ x = 0, and x ^ 0 = x. So, x ^ x ^ y = y
a' = a ^ b b' = b ^ a' = b ^ (a ^ b) = a a'' = (a ^ b) ^ a = b
This is pretty clever, I’ve never seen this for a swap.