Logic Gates
Reading the Gate Tables
The inputs are $A = 1$ and $B = 0$. Find the output of an AND, OR, XOR, NAND and NOR gate.
AND gate: AND needs both inputs to be 1, but $B = 0$ = AND: $0$
OR gate: OR needs at least one 1, and $A = 1$ = OR: $1$
XOR gate: The inputs $1$ and $0$ are different = XOR: $1$
NAND gate: NAND is the opposite of AND: AND gave $0$, so flip it = NAND: $1$
NOR gate: NOR is the opposite of OR: OR gave $1$, so flip it = NOR: $0$
Answer: AND $= 0$, OR $= 1$, XOR $= 1$, NAND $= 1$, NOR $= 0$. NAND and NOR are always the opposite of AND and OR.
AND Followed by NOT
$A$ and $B$ go into an AND gate, and its output goes into a NOT gate. Find the output $Y$ for all four input rows. Which single gate does the same job?
Write the input rows: Start with $0, 0$: the rows are $00$, $01$, $10$, $11$ = 4 rows
Output of the AND gate: AND is 1 only when both inputs are 1 = AND: $0, 0, 0, 1$
Output of the NOT gate: Flip every value of the AND column = $Y$: $1, 1, 1, 0$
Compare with the gate table: The column $1, 1, 1, 0$ is the NAND column = $Y = \overline{A \cdot B}$
Answer: The output is $1, 1, 1, 0$, so AND followed by NOT behaves exactly like a NAND gate. That is where the name NOT AND comes from.
Tracing a Three-Gate Circuit
$A$ and $B$ go into an OR gate. $B$ and $C$ go into an AND gate. The two outputs go into an XOR gate, which gives $Y$. Find $Y$ for $A = 0$, $B = 1$, $C = 0$.
First gate: OR of $A$ and $B$: $0 \lor 1$: at least one input is 1 = OR output $= 1$
Second gate: AND of $B$ and $C$: $1 \land 0$: not both inputs are 1 = AND output $= 0$
Last gate: XOR of the two outputs: The XOR gate gets $1$ and $0$, which are different = $Y = 1$
Check with the expression: $Y = (A \lor B) \oplus (B \land C) = 1 \oplus 0$ = $Y = 1$
Answer: $Y = 1$. The last gate never sees $A$, $B$ and $C$ directly: it only sees the outputs of the first two gates.
From Circuit to Boolean Expression
$A$ goes through a NOT gate. Its output and $B$ go into an AND gate. That output and $C$ go into an OR gate, which gives $Y$. Write the Boolean expression of the circuit and find $Y$ for $A = 1$, $B = 1$, $C = 0$.
Name the output of the NOT gate: The NOT gate flips $A$ = $\neg A$
Name the output of the AND gate: Its inputs are $\neg A$ and $B$ = $\neg A \land B$
Name the output of the OR gate: Its inputs are $\neg A \land B$ and $C$ = $Y = (\neg A \land B) \lor C$
Evaluate for $A = 1$, $B = 1$, $C = 0$: $\neg A = 0$, then $0 \land 1 = 0$, then $0 \lor 0 = 0$ = $Y = 0$
Answer: $Y = (\neg A \land B) \lor C$, which engineers write as $Y = \overline{A} \cdot B + C$. For $A = 1$, $B = 1$, $C = 0$ the output is $Y = 0$.
The Half Adder
A computer adds two binary digits $A$ and $B$. The result has a sum digit $S$ and a carry digit $C$ (for example $1 + 1 = 10$ in binary: $C = 1$, $S = 0$). Which gates produce $S$ and $C$?
List all four additions in binary: $0 + 0 = 00$, $0 + 1 = 01$, $1 + 0 = 01$, $1 + 1 = 10$ = Results: 00, 01, 01, 10
Read the sum column $S$ (right digit): $S$: $0, 1, 1, 0$, which is 1 only when the inputs are different = $S = A \oplus B$ (XOR)
Read the carry column $C$ (left digit): $C$: $0, 0, 0, 1$, which is 1 only when both inputs are 1 = $C = A \land B$ (AND)
Check $1 + 1$: $S = 1 \oplus 1 = 0$ and $C = 1 \land 1 = 1$, so the result is $10$ in binary = $10_2 = 2$ ✓
Answer: $S = A \oplus B$ and $C = A \land B$. One XOR gate and one AND gate form a **half adder**, the first building block of every calculator and computer.
Mistake: Thinking an OR gate gives $0$ when both inputs are $1$
Why: That is the XOR gate. OR is 1 when at least one input is 1, and that includes the case where both are 1.
Correct: OR: $1 \lor 1 = 1$. XOR: $1 \oplus 1 = 0$. Only XOR asks for the inputs to be different.
Mistake: Reading $A + B$ as ordinary addition and writing $1 + 1 = 2$
Why: In gate notation $+$ means OR, and the output of a gate can only be 0 or 1.
Correct: With gates, $1 + 1 = 1$ (OR). The value 2 only appears when you add binary numbers, and then it is written as $10$ with a carry digit.
Mistake: Treating NAND as NOT A AND NOT B, that is $\overline{A} \cdot \overline{B}$
Why: NAND flips the output of AND, not the inputs. For $A = 1$, $B = 0$: NAND gives $\overline{1 \cdot 0} = 1$, but $\overline{1} \cdot \overline{0} = 0 \cdot 1 = 0$.
Correct: NAND $= \overline{A \cdot B}$: first AND, then NOT. The bar covers the whole product.
Mistake: Feeding the original inputs into the last gate of a circuit
Why: In a circuit each gate only receives the wires connected to it. The last gate usually gets the outputs of earlier gates, not A, B and C.
Correct: Work from the inputs to the output, write the output of every gate next to it, and use those values for the next gate.
Alarm Systems
A home alarm is a small logic circuit: sensors give 1 or 0, gates decide whether the siren gets 1.
With armed switch $A$, door sensor $D$ and window sensor $W$, the alarm rings when $Y = A \land (D \lor W) = 1$.
Adding Numbers in a Chip
Every addition a computer does is built from half adders and full adders made of gates.
A half adder computes the sum digit $S = A \oplus B$ and the carry digit $C = A \land B$ of two binary digits.
Building Chips from NAND Gates
Chip makers like NAND gates because every other gate can be built from NAND gates alone.
Connect both inputs of a NAND gate to the same signal $A$: the output is $\overline{A \cdot A} = \overline{A}$, so it works as a NOT gate.
A logic gate takes inputs that are 1 (voltage on) or 0 (voltage off) and gives one output, also 1 or 0
AND gives 1 only when both inputs are 1; OR gives 1 when at least one input is 1; NOT flips its single input
XOR gives 1 when the inputs are different; NAND and NOR are the opposites of AND and OR
Gate notation: $A \cdot B$ (AND), $A + B$ (OR), $\overline{A}$ (NOT), $A \oplus B$ (XOR), and here $1 + 1 = 1$
To find the output of a circuit, go from the inputs to the output and write down the output of every gate
Name each gate's output as an expression to get the Boolean expression of the whole circuit
Q: Why do gates use 1 and 0 instead of true and false?
A: Inside a chip there are only voltages. A high voltage stands for 1 (true) and a low voltage for 0 (false). Using just two levels makes circuits fast and reliable, because a signal that is a little weaker still clearly reads as 1.
Q: What is the difference between OR and XOR?
A: They differ in only one row: when both inputs are 1. OR gives $1$ (at least one is on), XOR gives $0$ (the inputs are not different). XOR is the either-or-but-not-both gate.
Q: Why are NAND gates so popular?
A: Any other gate can be built from NAND gates alone. For example, a NAND with both inputs joined is a NOT gate. So a factory can make chips from one kind of gate. You will see the algebra behind this in the Boolean Algebra lesson.
Q: Can I check gates with ordinary arithmetic?
A: Yes, with 0 and 1: AND is $A \times B$, NOT is $1 - A$, OR is $A + B - A \times B$ and XOR is $A + B - 2 \times A \times B$. For example, OR for $1, 1$ is $1 + 1 - 1 = 1$. Try it in the calculator.
Logic Gates
1 / 14
Logic Gates
Learn how AND, OR, NOT, XOR, NAND and NOR gates turn 1s and 0s into decisions, and how to find the output of a small circuit.