Logic Gates
Every instruction a processor runs, from adding two numbers to comparing two passwords, ends up as a pattern of voltages switching between high and low. Logic gates are the smallest circuits that act on those patterns. Once you can read a gate symbol and predict its output, you can trace a digital circuit by hand, which is a core skill in computer organization and digital logic courses.
Bits in, one bit out
A logic gate is a circuit that takes one or more binary inputs and produces a single binary output according to a fixed rule. In a real chip, 1 stands for a high voltage and 0 for a low voltage, but you can reason about gates using the digits alone.
The complete behaviour of a gate or circuit is captured by a truth table: one row for every possible combination of inputs, together with the resulting output. Each input has two possible values, so a circuit with n inputs needs
Two inputs give 4 rows, three give 8 and four give 16. List the input rows in binary counting order (00, 01, 10, 11) so you never skip or repeat a combination.
The six basic gates
Most circuits are drawn from six gates: AND, OR, NOT, NAND, NOR and XOR. In their Boolean expressions a dot means AND, an overbar means NOT and + means OR.
Gate | Expression | Output is 1 when |
|---|---|---|
AND | Q=A⋅B | every input is 1 |
OR | Q=A+B | at least one input is 1 |
NOT | Q=A | the single input is 0 |
NAND | Q=A⋅B | at least one input is 0 |
NOR | Q=A+B | every input is 0 |
XOR | Q=A⊕B | the two inputs differ |
For two-input gates, the full truth tables side by side are:
A | B | AND | OR | NAND | NOR | XOR |
|---|---|---|---|---|---|---|
0 | 0 | 0 | 0 | 1 | 1 | 0 |
0 | 1 | 0 | 1 | 1 | 0 | 1 |
1 | 0 | 0 | 1 | 1 | 0 | 1 |
1 | 1 | 1 | 1 | 0 | 0 | 0 |
NAND and NOR are simply AND and OR with their outputs inverted, so each NAND column is the opposite of the AND column, and likewise for NOR and OR. The small circle on their symbols is an inversion bubble: a bubble on any gate symbol means the signal is inverted at that point.
Combining gates into circuits
Real circuits chain gates, so the output of one gate becomes an input of the next. To find the circuit output, evaluate gates in order from the inputs toward the output, writing down the value on each intermediate wire.
Example: Suppose Q=A⋅B, so a NOT gate inverts A and an AND gate combines the result with B. With A = 0 and B = 1, the NOT gate outputs 1 and the AND gate receives 1 and 1, so Q = 1. With A = 1 and B = 1, the NOT gate outputs 0 and Q = 0.
The same method builds a complete truth table for a circuit: add one column for each intermediate wire, fill those columns row by row, then compute the output column from them.
What to remember
- A logic gate maps binary inputs to one binary output by a fixed rule.
- A truth table for n inputs has 2n rows; list them in binary counting order.
- AND needs every input to be 1, OR needs at least one 1, XOR needs the inputs to differ, and NOT inverts.
- A bubble means inversion: NAND and NOR are inverted AND and OR.
- Trace a circuit from inputs to output, recording each intermediate wire.
Example: Tracing a greenhouse alarm circuit
A greenhouse controller reads three sensor signals. A = 1 when the heater is running, B = 1 when the roof vent is open, and C = 1 when the backup thermostat reports normal operation. The alarm Q should sound (Q = 1) when the heater runs with the vent open, wasting heat, or when the thermostat stops reporting normal operation. The circuit below implements this with one AND gate, one NOT gate and one OR gate.
a) Write the Boolean expression for each intermediate wire, X and Y, and then for the output Q.
Inputs A and B both feed the AND gate, so the wire leaving it carries X = A·B.
Input C passes through the NOT gate, so the wire leaving it carries Y = NOT C.
The OR gate combines the two wires:
This matches the specification: the alarm sounds for heater-with-vent-open, or for a thermostat fault, or both.
b) Build the full truth table for Q, including the intermediate wires X and Y.
With three inputs the table needs 23 = ________ rows. List them in binary counting order and evaluate X = A·B, then Y = NOT C, then Q = X OR Y:
- A = 0, B = 0, C = 0: X = 0, Y = 1, so Q = 1.
- A = 0, B = 0, C = 1: X = 0, Y = 0, so Q = 0.
- A = 0, B = 1, C = 0: X = 0, Y = 1, so Q = 1.
- A = 0, B = 1, C = 1: X = 0, Y = 0, so Q = 0.
- A = 1, B = 0, C = 0: X = 0, Y = 1, so Q = 1.
- A = 1, B = 0, C = 1: X = 0, Y = 0, so Q = 0.
- A = 1, B = 1, C = 0: X = 1, Y = 1, so Q = 1.
- A = 1, B = 1, C = 1: X = ________, Y = ________, so Q = 1.
The alarm sounds in five of the eight rows. It stays silent only in the three rows where the thermostat is normal (C = 1) and the heater and open vent are not both present.
c) The roof vent is jammed shut, so B = 0. Under what condition does the alarm sound, and does the heater signal A matter?
With B = 0 the AND gate outputs X = ________ whatever the value of A, because AND needs every input to be 1. The OR gate then passes Y straight through:
The rows of the truth table with B = 0 and Q = 1 are (A, B, C) = (0, 0, 0) and (1, 0, 0), which is ________ of the four rows with the vent shut. Both have C = 0.
So with the vent shut, the alarm sounds exactly when C = 0, a thermostat fault, and the heater signal A has no effect on the output.
A designer needs a two-input gate for a parity circuit. Its output must be 1 exactly when the two input bits are different and 0 when they are the same. Which gate should the designer use?
De Morgan's laws let you rewrite a negated OR as an AND of negated inputs. Complete the truth table below for two inputs A and B, entering 0 or 1 in every empty cell, and compare the column for NOT (A OR B) with the column for NOT A AND NOT B.
| A | B | A OR B | NOT (A OR B) | NOT A | NOT B | NOT A AND NOT B |
| 0 | 0 | |||||
| 0 | 1 | |||||
| 1 | 0 | |||||
| 1 | 1 |