[Solved] How to swap two variables using bitwise operators (not XOR, and without temporary var) [closed]
XOR, p ^ q, can be expressed using the and (&), or (|), and not/invert (~) bitwise operators as (p & q) | ~(p & q) (see Wikipedia’s exclusive or article). Hence, we can now simulate an XOR with the other bitwise operators to do the usual swap. int x = 1; int y = … Read more