XOR operation to swap to value without additional variable I'm breaking my mind to find a good explanation to split two variables with the XOR operation.
The operation is the following:
x ^= y # =&gt;                      (x ^ y, y)
y ^= x # =&gt; (x ^ y, y ^ x ^ y) = (x ^ y, x)
x ^= y # =&gt; (x ^ y ^ x, x)     = (y, x)

and my doubt is about the second line, in particular (x ^ y, y ^ x ^ y) = (x ^ y, x)  how I can have the result X from the operation y ^ x ^ y?
I know that y^y = 0, but in the previous case I can not say that y^x^y is equal to x.
What I'm losing here?
Source
First, xor is commutative and associative, therefore (a xor b) xor c = a xor (b xor c) = a xor (c xor b) = (a xor c) xor b, and in your case that means (x xor y) xor x = (x xor x) xor y = 0 xor y = y.
But this is just a rather pointless programming trick. It only works for integers, it can't be used for floating point numbers, strings, booleans, pointers etc., so it is pointless. It wouldn't pass any code review, so you can't ever use it in real life.