XOR in C++
- http://www.codeguru.com/forum/archive/index.php/t-179920.html
- http://bytes.com/groups/c/215986-why-isnt-there-logical-xor-operator
Final Recommendation:
-
// 'a' and 'b' are some sort of integer type.
-
// the double NOTs coerce to a standard boolean type
-
// (compiler dependent)
-
!!a ^ !!b
Thankfully Java is easier
http://www.sap-img.com/java/java-boolean-logical-operators.htm
-
// 'a' and 'b' are of boolean type
-
// yay, no coercion necessary!
-
a ^ b
I didn’t know that the ^ operator was overloaded to handle Booleans, until I needed it a few weeks ago.
Comments
Leave a comment Trackback