XOR swap algorithm in python?

Posted by TheMachineCharmer on Stack Overflow See other posts from Stack Overflow or by TheMachineCharmer
Published on 2010-03-16T05:40:42Z Indexed on 2010/03/16 5:46 UTC
Read the original article Hit count: 358

Filed under:
|
|

I tried to implement XOR sort in python.

x,y= 10,20

x,y,x = x^y,x^y,x^y

print('%s , %s'%(x,y))

OUTPUT:

30 , 30

I am not new to python but I am unable to explain this output. It should have been 20,10.

What is going on under the hood?

© Stack Overflow or respective owner

Related posts about python

Related posts about algorithm