Jump to content

Basic C++ :: XOR Gates

- - - - -

  • Please log in to reply
4 replies to this topic

#1
v o i d

v o i d

    Newbie

  • Members
  • Pip
  • 2 posts
Basic C++ :: XOR Gates

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

#2
AKMafia001

AKMafia001

    Programmer

  • Members
  • PipPipPipPip
  • 119 posts
This might be a tutorial... Well the moderator will move it to the tutorial section soon!
I think i'm able to write a code for printing "Hello, World!". Proud of that!

#3
v o i d

v o i d

    Newbie

  • Members
  • Pip
  • 2 posts
Sorry, I didn't realise there was a tutorial section.

#4
AKMafia001

AKMafia001

    Programmer

  • Members
  • PipPipPipPip
  • 119 posts
Don't worry! It will be moved soon...
I think i'm able to write a code for printing "Hello, World!". Proud of that!

#5
Flying Dutchman

Flying Dutchman

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 889 posts
  • Location:::1
C++ does support (bit-wise) XOR. It's ^ operator.
A conclusion is where you got tired of thinking.
#define class struct    // All is public.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users