i am a novice to electronics,actually i am java and android developer who doesn't know the very basic concepts of computing and trying to learn from ground level. i was checking out a video which explains about logical gates very well but i did not understand on thing in this pic:

the xor gate has NAND gate and OR gates with output connecting to AND gate so if both switches are on out put of right bulb will be off. my question is if instead of XOR gate we put just NAND gate isn't it gonna be same thing? because all we want is output off if both switches are on.

• XOR gate's truth table and NAND truth table aren't same. What if both inputs are zero? Its supposed to be 0 but NAND gives different. – Umar Mar 20 '17 at 12:04
• hi thanx,thank you,but how nand gate gives output 1 while its inputs are off? – Nav Sandhu Mar 20 '17 at 12:12
• A NAND gate gives output 1 if either input is off, which includes the case of both inputs being off. – Dave Tweed Mar 20 '17 at 12:31
• You may be missing the idea that gates have their own power supply, not always shown on diagrams. – pjc50 Mar 20 '17 at 13:28

my question is if instead of XOR gate we put just NAND gate isn't it gonna be same thing? because all we want is output off if both switches are on.

Nope. In binary,

0 + 0 =  00
0 + 1 =  01
1 + 0 =  01
1 + 1 =  10


As you can see, a NAND gate would give incorrect results (the first line would have 0+0=01 instead of 00).

• thank you,but how nand gate gives output 1 while its inputs are off? – Nav Sandhu Mar 20 '17 at 12:02
• Well, check out the truth table of NAND gate ;) en.wikipedia.org/wiki/NAND_gate – peufeu Mar 20 '17 at 12:42
• @NavSandhu gates don't exist in isolation, they have separate supply and ground lines that aren't shown in logic diagrams. – ratchet freak Mar 20 '17 at 14:20

These are all examples of XOR Boolean logic.

Either input high, otherwise low = EXCLUSIVE OR

simulate this circuit – Schematic created using CircuitLab