Is the bitwise XOR return value used incorrectly?

I replaced the values โ€‹โ€‹of two integers with XOR-swap, and for this I used the following line of code:

a ^= (b ^= (a ^= b)); 

Then b gets the correct value (the old value of a ), but a becomes zero. If I do not write it on one line, it works fine, for example:

 a ^= b; b ^= a; a ^= b; 

Am I doing something wrong, or are netbeans / compiler / JRE doing something wrong? (using netbeans 7.2.1)

+4
source share

All Articles