Logic Gates: NAND, NOR, XOR
On this page, you will explore some more complex logic gates: NAND, NOR and XOR.
NAND gate: not AND
A NAND gate is a logic gate that behaves exactly like the Boolean operator NAND which is the composition of NOT and AND operators. The output of the NAND gate is 1 if and only if both of its inputs are 0, just as the output of the Boolean operator NAND is True if and only if both of its inputs are False. In the truth tables below you can see the correspondence between the Boolean operator NAND and the NAND gate. In the tables, A and B represent the two binary inputs (False/True and 0/1) which are represented by the two wires going into the NAND gate in the picture shown above.
You may find the following correspondence in set theory helpful:
An element is in A
NAND B if and only if it is
not in A
AND B (intersection).
The following electric circuit may give you an idea how it is possible to emulate the Boolean operator NAND electronically.
The light bulb is ON only if it is not the case that both of the switches are ON.
Daily Life Application:
- A mechanism for a safe that releases a lock only when both of two keys are used.
- Examine the Snap! file and all its sprites. For the sprite
A nand B
, assemble some code blocks to emulate a NAND gate.
NOR gate: not OR
A NOR gate is a logic gate that behaves exactly like the Boolean operator NOR which is the composition of NOT and OR operators. The output of the NOR gate is 1 if and only if both of its inputs are 0, just as the output of the Boolean operator NOR is True if and only if both of its inputs are False. In the truth tables below you can see the correspondence between the Boolean operator NOR and the NOR gate. In the tables, A and B represent the two binary inputs (False/True and 0/1) which are represented by the two wires going into the NOR gate in the picture shown above.
You may find the following correspondence in set theory helpful:
An element is in A
NOR B if and only if it is
not in A
OR B (union).
The following electric circuit may give you an idea how it is possible to emulate the Boolean operator NOR electronically.
The light bulb is ON only if it is not the case that either or both of the switches are ON. Said another way, the light bulb is ON only if both of the switches are OFF.
Daily Life Application:
- A mechanism for a safe that releases a lock only when either one (or both) of two keys are used.
- Examine the Snap! file and all its sprites. For the sprite
A nor B
, assemble some code blocks to emulate a NOR gate.
Universal Gates: NAND, NOR
NAND and NOR gates are called universal gates as each alone can emulate NOT, AND, and OR gates.
- In the animation below you can see how NAND gates are used to respectively emulate NOT, AND and OR gates. Explain how these work. How can you similarly use only NOR gates to emulate NOT, AND and OR gates?
- Examine the Snap! file and all its sprites. For the
NOT
, AND
, OR
sprites define the nand
block and assemble some code using nand
blocks to emulate the NOT, AND and OR gates.
XOR gate: Exclusive OR
An XOR gate is a logic gate that behaves exactly like the Boolean operator XOR (which stands for "eXclusive OR). The output of the XOR gate is 1 if and only if either but not both of its inputs are 1, just as the output of the Boolean operator XOR is True if and only if either but not both of its inputs are True. In the truth tables below you can see the correspondence between the Boolean operator XOR and the XOR gate. In the tables, A and B represent the two binary inputs (False/True and 0/1) which are represented by the two wires going into the XOR gate in the picture shown above.
You may find the following correspondence in set theory helpful:
An element is in A
XOR B if and only if it is in A or in B but
not in both.
A XOR B is logically equivalent to either of these:
- A XOR B = (A OR B) AND (NOT (A AND B)) -In English "Either A or B but not both"
- A XOR B = (A AND NOT B) OR (NOT A AND B)
Daily Life Application:
- A mechanism that allows access to a resource when either of two users but not both attempts to unlock.
- Examine the Snap! file and all its sprites. For the sprite
A xor B
, assemble some code blocks to emulate an XOR gate.
XOR gate from AND, OR, NOT
You can create the XOR gate from AND, OR and NOT gates as shown below. This set up follows directly from the logical identity given above:
A XOR B = (A OR B) AND (NOT (A AND B))
- Examine the Snap! file and all its sprites. Code for the
OR
sprite has been written for you. For the sprites AND1
, not
, and AND2
, assemble some code blocks to emulate an XOR gate.