Digital Logic
How to turn a logic expression into a gate circuit
To turn a logic expression into a circuit, build it from the inside out. Each operator becomes a gate. The part in brackets is worked out first, so its gate sits nearest the inputs; the operator outside every bracket is worked out last, so its gate drives the output. A gate's output is just a wire, so it feeds the next gate's input like a switch would.
From a sentence to gates
"The car starts when the key is turned and either pedal is pressed." Find the logic words, and bracket the part that belongs together, "either pedal":
The dot is AND and the plus is OR. The bracket comes first: an OR takes BRAKE and CLUTCH. Then an AND takes KEY and the OR's output, and drives START. Two gates in a chain.
Check one row: KEY = 1, BRAKE = 0, CLUTCH = 1. The bracket is 0 + 1 = 1, then 1 · 1 = 1, so the car starts.
Live experiment
Move the brackets
Three switches, an OR and an AND. Choose (A OR B) AND C and the OR goes first; choose A OR (B AND C) and the AND goes first. Both answers show all the time. Flip the switches until the two rules disagree, and find every setting where they do.
“Gates in a row” is lesson 4 of 6 in Gate Grove, Digital Logic World 1. Free with an account. Lessons unlock in order, so you’ll do the 3 before it first.
The other way round
A porch light comes on when it's dark and something moves, or whenever the override switch is on:
Now the AND is inside the bracket, so it goes first, nearest the switches, and the OR is last, nearest the light. Its truth table has five 1s: all four rows with OVERRIDE on, plus DARK and MOTION together with OVERRIDE off.
Moving the brackets changes the circuit
(A + B) · C and A + (B · C) use the same letters and the same two gates, but they're different rules:
| A | B | C | (A + B) · C | A + (B · C) |
|---|---|---|---|---|
| 1 | 0 | 0 | 0 | 1 |
| 1 | 1 | 0 | 0 | 1 |
On the other six rows they agree. In the first rule C is always needed; in the second, A alone is always enough. Get the brackets wrong in the porch light, DARK · (MOTION + OVERRIDE), and the override would only work in the dark.
Reading a circuit back
The same rule works in reverse. Start at the output gate, write its operator, and for each input write whatever drives it, putting a bracket round every gate you pass through. You end with the expression the circuit computes, ready to simplify with Boolean algebra.
Free lesson
Now build it yourself
Each lesson comes in three short parts: see the idea, try it on a live board, then build it yourself, with quick checks as you go.
“Gates in a row” is lesson 4 of 6 in Gate Grove, Digital Logic World 1. Free with an account. Lessons unlock in order, so you’ll do the 3 before it first.
Or start from the very first lesson, no account neededPractice questions
Three quick questions from the lessons. Pick an answer to check it.
Show the answer
Answer: 1. Brackets first, BRAKE OR CLUTCH is 0 OR 1, which is 1. Then KEY AND 1 is 1 AND 1, which is 1. The car starts.
- Why not “0”? The bracket is BRAKE OR CLUTCH, 0 OR 1, which is 1. Then KEY AND 1 is 1, so START is 1.
- Why not “Can't tell”? Every input is known, so the output is fixed: work out the bracket first, then the AND.
- Why not “2”? Logic outputs are 1 or 0. Two 1s into an AND give 1, not 2.
Show the answer
Answer: 0 and 1. (A OR B) AND C is 1 AND 0, which is 0: C is off. A OR (B AND C) is 1 OR 0, which is 1: A alone is enough. Same switches, different answers.
- Why not “0 and 0”? A OR (B AND C) has A alone on one side of the OR, and A is 1, so the second rule gives 1.
- Why not “1 and 0”? That's the two answers swapped. (A OR B) AND C is 0 because C is off, and A OR (B AND C) is 1 because A is on.
- Why not “1 and 1”? (A OR B) AND C needs C on, and C is 0 here, so the first rule gives 0.
Show the answer
Answer: The AND. The bracket is worked out first, so the AND takes DARK and MOTION, and its output goes into the OR with OVERRIDE. The OR is last, nearest the probe.
- Why not “A NOT”? There's no NOT in this rule. Its two gates are an AND inside the bracket and an OR outside it.
- Why not “Either, it doesn't matter”? Order matters: building the OR first gives DARK AND (MOTION OR OVERRIDE), a different table.
- Why not “The OR”? The OR is outside the bracket, so it's worked out last, nearest the light, joining the AND's output with OVERRIDE.
“Gates in a row” is lesson 4 of 6 in Gate Grove, Digital Logic World 1. Free with an account. Lessons unlock in order, so you’ll do the 3 before it first.
Questions people ask
Which gate do I draw first?
The innermost bracket, nearest the inputs. Each operator outside it takes that gate's output as one of its inputs, so the last operation, the one outside every bracket, is the gate that drives the output.
Does AND come before OR without brackets?
By the usual convention, yes: NOT first, then AND, then OR, just as multiplying comes before adding. So A + B · C means A + (B · C). Brackets make it unmistakable, and a circuit drawing shows the order exactly.
Can one input feed more than one gate?
Yes. A wire can go to as many gate inputs as it needs, which is called fan-out. What a wire must never have is two outputs driving it at once.
Related topics
- How to make a truth tableEvery input combination and its output: the complete, unarguable description of a logic circuit.
- Boolean algebra rules, with worked examplesThe handful of laws that simplify any logic expression, and how to turn a truth table into gates.
- Logic gates explainedAND, OR, NOT, XOR and their bubbled twins: each one's rule is a truth table.
- AND and NOT gates explainedAND needs every input at 1; NOT flips its one input. Together they build safety interlocks and masks.