Why is there no "Logical XOR" in C++?

Asked

Viewed 183 times

6

I was thinking and I came up with this question:

Why is there "Bitwise OR", "Bitwise AND" and "Bitwise XOR", if in Boolean logic there is only "Logical OR" and "Logical AND".

There should be the "Logical XOR"!

For example:

true  false = true
true  true  = false
false true  = true
false false = false

1 answer

9


There is yes, look at it, gives the result you want, it just doesn’t call Logical XOR because it already has a simpler name, it is called different, because that’s what he is, he gives true when the operands are different, equal to the bitwise XOR, can test:

#include <iostream>
using namespace std;

int main() {
    cout << (true != false) << endl;
    cout << (true != true) << endl;
    cout << (false != true) << endl;
    cout << (false != false) << endl;
}

Behold working in the ideone. And in the repl it.. Also put on the Github for future reference.

  • makes sense! I didn’t think of that

Browser other questions tagged

You are not signed in. Login or sign up in order to post.