XOR gate - Wikipedia, the free encyclopedia
C++ does not define a logical operator that performs an exclusive-OR operation,
usually referred to as XOR. XOR is a binary operation that yields true when and only one operand is true.
What you need:
A Brain,
Patience,
A C++ IDE,
The ability to read.
1. Create a new console application called XOR.cpp
2. Assuming there are two boolean values a XOR is constructed like this:
(p||q)&&(p && q)
3. Now enter this code into the main() function in your C++ program.
It demonstrates the XOR operation for 2 combinations of true/false values.
bool p, q; p = true; q = true; cout << p << " XOR " << q << " is " << (( p || q ) && ! ( p && q )) << "\n"; p = false; q = true; cout << p << " XOR " << q << " is " << (( p || q ) && ! ( p && q )) << "\n";
4. The output should look like this:
1 XOR 1 is 0 0 XOR 1 is 1
References: C++ , A Beginners Guide. By Herbert Schildht


Sign In
Create Account

Back to top









