Logic Gates: NAND, NOR, XOR

On this page, you will explore some more complex logic gates: NAND, NOR and XOR.

NAND gate: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.

Truth table for NAND with True/FalseTruth table for NAND with 1/0
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).
Venn diagram fro NAND

The following electric circuit may give you an idea how it is possible to emulate the Boolean operator NAND electronically.

Electric circuit for NAND

The light bulb is ON only if it is not the case that both of the switches are ON.

Daily Life Application:
  1. Click here to load this file. Then save it to your Snap! account.
  2. 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: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.

Truth table for NOR with True/FalseTruth table for NOR with 1/0
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).
Venn diagram for NOR

The following electric circuit may give you an idea how it is possible to emulate the Boolean operator NOR electronically.

Electric circuit for NOR

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:
  1. Click here to load this file. Then save it to your Snap! account.
  2. 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.

  1. 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?
  2. NAND as universal gate
  3. Click here to load this file. Then save it to your Snap! account.
  4. 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: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.

Truth table for XOR with True/FalseTruth table for XOR with 1/0
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.
Venn diagram  for XOR

A XOR B is logically equivalent to either of these:
Daily Life Application:
  1. Click here to load this file. Then save it to your Snap! account.
  2. 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))
XOR from AND, OR, NOT
  1. Click here to load this file. Then save it to your Snap! account.
  2. 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.