c94wjpn
June 20th, 2002, 08:38 AM
:D Hi folks. is there an XOR binary (bool,bool) operator in C++ please?
|
Click to See Complete Forum and Search --> : xor c94wjpn June 20th, 2002, 08:38 AM :D Hi folks. is there an XOR binary (bool,bool) operator in C++ please? Graham June 20th, 2002, 08:49 AM Presumably you mean logical XOR as opposed to bitwise XOR (the ^ operator). No. Use: (a || b) && !(a && b) Pete Bourner June 20th, 2002, 09:37 AM A better way to do this is : ( a != b ). This will obviously only be true if one of a and b is TRUE and the other is FALSE. If you wanted to, you could even define XOR to be !=, as in the following: #define XOR != int main(int argc, char* argv[]) { bool a = ( false XOR false ); bool b = ( false XOR true ); bool c = ( true XOR false ); bool d = ( true XOR true ); return 0; } This approach makes the intention of the code just as clear as an inbuilt xor operator would. c94wjpn June 20th, 2002, 11:50 AM ok thanks codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |