xor the two numbers in place swap?
I came across a question with swapping two numbers using xor. so the it's basically x=x^y; y=x^y; x=x^y
x=x^y; y=x^y; x=x^y
x=x^y; y=x^y; x=x^y
, and i can think of y=(x^y)^y=x
,so that y now becomes x, but on the last one wouldn't it be x=x^y = (x^y)^(x^y)= 0?
how does x become y?
x=x^y
y=(x^y)^y
x=(x^y)^((x^y)^y) //here is how you get x = y
你做了错误的替代。
链接地址: http://www.djcxy.com/p/58206.html上一篇: PhantomJs点击链接或运行
下一篇: XOR这两个数字在原地换?