The NAND Gate
The NAND logic gate is a fundamental building block of computers.
The output (Q) is only off when both inputs (A and B) are on. This can be expressed using the following truth table.
INPUT | OUTPUT | |
A | B | A NAND B |
0 | 0 | 1 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 0 |
STOP RIGHT HERE: I know, we’ve only just begun. This gate is so fundamental to understanding the rest of this text that you need to be able to look the values of the inputs of this gate and immediately see the value of the output. Create 4 flashcards. On each one draw a NAND gate with one of the 4 possible input combinations and on the back draw the output value. Study these flashcards until you’ve committed them to memory.
The NOT Gate
The NOT gate can be constructed using a NAND gate by connecting both inputs of the NAND gate to a single input as shown below.
Since the NOT is just a NAND gate but with fewer input combinations (both on or both off), the truth table for the NOT gate consists of just two rows from the truth table for the NAND gate.
INPUT | OUTPUT |
A | NOT A |
0 | 1 |
1 | 0 |
The NOT gate is usually drawn, not using a NAND gate, but as shown below.
The AND Gate
An AND gate can be constructed using two NAND gates.
Notice that the second NAND gate is a NOT gate. Thus, the output of the AND gate simply inverts the output of the first NAND gate. Here the output is on only if both input are on.
INPUT | OUTPUT | |
A | B | A AND B |
0 | 0 | 0 |
0 | 1 | 0 |
1 | 0 | 0 |
1 | 1 | 1 |
The AND gate too has its own symbol:
Notice that it is similar to a NAND gate, just without the small circle at the tip of the D curve.
The OR Gate
The OR gate can also be constructed using NAND gates and NOT gates.
The truth table follows:
INPUT | OUTPUT | |
A | B | A OR B |
0 | 0 | 0 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 1 |
The symbol for the OR gate is below.
The XOR Gate
The last gate that we’ll need is the XOR gate. It too can be constructed with only NAND gates.
The XOR’s output is 1 if only one of the inputs is 1, otherwise the output is 0 as shown in the truth table.
INPUT | OUTPUT | |
A | B | A XOR B |
0 | 0 | 0 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 0 |
The symbol used for the XOR gate is below.
Alternate AND, OR and XOR Gate Construction
Below is a diagram showing the NOT, AND, OR and XOR gates. These are equivalent to the above constructions.