What is the most elegant way to do the next stuff:
int i = oneOrZero; if (i == 0) { i = 1; } else { i = 0; }
You can assume that i can have only 1 or 0 value.
i
i ^= 1;
XOR the value with 1. This gives you both ways (in case you need to flip 0 <--> 1 either way):
0 <--> 1
0 ^ 1 = 1 1 ^ 1 = 0
1.4m articles
1.4m replys
5 comments
57.0k users