I want to swap the value of two integer variables in java using the XOR operator.
This is my code:
int i = 24; int j = 17; i ^= j; j ^= i; i ^= j;
The left-most i is being evaluated before it's changed.
i
You can instead do:
j ^= (i ^= j); i ^= j;
Which is slightly less compact but works.