Swap two variables using XOR

x=x*y;
y=x/y;
x=x/y;

it’s amazing explanation thnks alot

Have you checked this Write a program to Swap two variables or number.One can find almost all the methods of swapping of two numbers.

In python: a,b = b,a

nice thank you

I made the same observation that anonymous mentioned (comment # 19) about the generated code, so I made a retail build of the experiment program in which I tested it, and ran it, to satisfy myself that it worked. The code generated to implement the XOR swap is as follows, where the data to be swapped was already in registers EDI and EBX.

xor	edi, ebx
xor	ebx, edi

This was done with Visual C++ 2013.

Very sweet!