Boolean Logic
The six gates every circuit is built from, and the four questions the exam asks about them.
WATCH IT EXPLAINED
EXPLORE IT IN 3D
The logic bench
A breadboard, six real logic chips, switches and LEDs. Name gates by testing them, build circuits from expressions, tables and sentences — and prove NAND alone can build them all.
What a gate actually is
A logic gate is a fixed rule that turns one or two inputs of 0 or 1 into one output.
A logic gate is a rule. You do not have to understand it electrically.
- One or two wires go in. One wire comes out.
- Every wire is either OFF (written
0) or ON (written1). It is never anything in between. - The gate's rule says what the output is for each setting of the inputs.
- That rule never changes.
Remember:There are six gates, so six rules. Learn them, and everything else in this topic is bookkeeping (careful writing down).
1 = ON = true = high
0 = OFF = false = lowThe six gates, in one table
Six gates, six rules: learn this table by heart, because every logic question starts from it.
This is the table everything else depends on. You must be able to write it from memory without hesitating. Every question below starts by looking a row up in it.
| 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 |
NOT has one input: NOT 0 = 1 and NOT 1 = 0.
- AND is 1 only when BOTH are 1.
- OR is 1 when AT LEAST ONE is 1.
- NAND is 0 only when BOTH are 1. It is AND with the answer flipped (NOT AND).
- NOR is 1 only when BOTH are 0. It is OR with the answer flipped (NOT OR).
- XOR is 1 when they are DIFFERENT. It is the awkward one: one or the other, but NOT both.
Three ways of writing the same thing
A circuit, an expression and a truth table say the same thing; every question asks you to translate one into another.
There are three ways of writing one idea:
- a circuit: a drawing of gates and wires
- a logic expression: the circuit on one line, like
Q = (A AND B) OR C - a truth table: every setting of the inputs, with the output beside it
The whole of this topic is translating between them. Every logic question on the paper is one of four translations. Each one has a method you can follow without being clever.
| Question | Translation | The paper says |
|---|---|---|
| 1 | expression → circuit | "draw a logic circuit for..." |
| 2 | circuit → truth table | "complete the truth table..." |
| 3 | circuit → expression | "write a logic expression for..." |
| 4 | truth table → expression | "write the logic expression for..." |
The four notes after this one are those four methods.
Question 1 — draw the circuit for an expression
Draw from the inside out: the innermost brackets give the first gate, and the outside operation gives Q.
Work from the inside out. The brackets tell you the order.
| Which gate | Where you find it in the expression |
|---|---|
| the FIRST gate you draw | inside the innermost brackets |
the LAST gate you draw (its output is Q) | the operation written outside all the brackets |
Give every input its own line on the left. If the same input is used twice, let its line split.
Example:NOT (A OR (B AND C)). Draw B AND C first. Then draw the OR with A. The NOT is last, and its output is Q.
METHOD
1. Find the innermost brackets. Draw that gate first.
2. Work outwards, one bracket at a time.
3. The operation outside everything is the last gate. Its output is Q.
CHECK: read your own circuit back as words. "NOT (A OR (B AND C))".
If it does not read the same as the question, a wire is wrong.Question 2 — complete the truth table for a circuit
Fill a truth table one column at a time, one gate per column, never a whole row at once.
Do not try to do a whole row in your head. Instead:
- Give every gate in the circuit a letter.
- Add one column per gate.
- Fill the table column by column, left to right.
Each column only ever depends on columns you have already filled. So you never do more than one gate at a time.
Exam:The intermediate output columns (the outputs of gates in the middle of the circuit) are worth marks on their own. Write them even when the question only asks for the final output.
METHOD
1. Label every gate output: X, Y, Z...
2. Write the input rows in binary counting order (see the last note).
3. One column per label, then the final output column.
4. Fill each column completely before starting the next.Question 3 — write the expression for a circuit
Walk from the inputs to Q, writing each gate's output on its wire; the last wire holds the answer.
This is question 1 backwards, and it is easier. You can do it with a pencil on the diagram itself.
- Start at the inputs and walk forwards.
- Write the output of each gate ON the wire that leaves it, in brackets.
- When you reach the final gate, the thing written on its output wire is the answer.
Example:The last wire carries (A AND B) OR (NOT C), so Q = (A AND B) OR (NOT C).
METHOD
1. Write A, B, C on the input wires.
2. For each gate, write what comes OUT of it on its output wire,
in brackets: (A AND B), (NOT C), and so on.
3. Keep going until you reach Q. Copy down what is written there.
Q = (A AND B) OR (NOT C)
Brackets round a single NOT can be dropped: Q = (A AND B) OR NOT C.
Never drop brackets round an AND, OR or XOR, or the brackets after a NOT.Question 4 — write the expression for a truth table
Take each row where the output is 1, turn it into an AND term, and join the terms with OR.
This one looks impossible, but it is the most mechanical of the four. Its name is sum of products.
- Look only at the rows where the output is
1. Ignore every other row completely. - Turn each of those rows into one
ANDterm. - Join the terms with
OR.
Remember:The method never fails, whatever the table says. It is worth full marks even when a shorter answer exists.
METHOD -- the name for it is SUM OF PRODUCTS
1. Look down the output column. Circle every row where it is 1.
2. Turn each circled row into one AND term:
write every input that is 1 as itself,
write every input that is 0 with a NOT,
join them with AND.
3. Join all the terms together with OR. That is the answer.
TO DRAW IT: one AND term per circled row (with the NOTs in front). With
three inputs each term is two AND gates chained, because a gate has at
most two inputs. Then join the terms with ORs: n terms need n - 1
two-input ORs. For this table, two circled rows of three inputs means
four ANDs and one OR.
CHECK: count your AND terms. It must equal the number of circled rows.When the long method is not the short answer
Sum of products always works, but some common tables have a much shorter answer.
The sum-of-products method always works. Sometimes it works far too hard.
Before you write eight gates, look at the output column as a whole. Ask: what is it describing?
A few tables come up again and again. Each one has a far shorter answer than the long method gives. The box below lists them.
Exam:The short answer is not required for the marks on a "write the expression" question. It is required whenever the question says "simplify". It also saves you a page of drawing.
Only ONE row has output 0
-> that is NAND (0 only when both are 1)
or OR (0 only when both are 0)
The long method would give you three AND terms for the SAME thing.
Only ONE row has output 1
-> that is AND (1 only at 1 1)
or NOR (1 only at 0 0)
For NOR the long method gives (NOT A) AND (NOT B): three gates, not one.
The output is 1 when the inputs are DIFFERENT
-> XOR. Two inputs, one gate.
The output is 1 when an ODD number of inputs are 1
-> XOR chained: (A XOR B) XOR C. Two gates instead of four AND terms.
The output is 1 when AT LEAST TWO of three inputs are 1
-> (A AND B) OR (A AND C) OR (B AND C). Three AND terms, not four.
ALWAYS worth doing: if two of your AND terms are identical except that one
has X and the other has NOT X, that variable drops out and the two terms
become one. (A AND B) OR (A AND NOT B) = ATurning a sentence into logic
Give each condition a letter, then turn the joining words, like "and", "or" and "unless", into gates.
Paper 2 often gives you a situation in words instead of a table: a safety system, a vending machine, a car.
- Give each condition a letter first, and write the letters down. Half the marks lost here are lost by mixing up which letter meant what.
- Then look for the joining words. They translate one for one into gates.
| Joining words | Gate |
|---|---|
| and | AND |
| or | OR |
| not / unless / fails | NOT |
| either ... or ... but not both | XOR |
| neither ... nor ... | NOR |
and -> AND
or -> OR
not / unless / fails -> NOT
either ... or ... but not both -> XOR
neither ... nor ... -> NOR
WORKED
"The machine runs when the guard is closed (G) AND the button is
pressed (B), unless the emergency stop is pressed (E)."
G = 1 when the guard is closed
B = 1 when the button is pressed
E = 1 when the emergency stop is pressed
"unless E" means AND NOT E
M = (G AND B) AND (NOT E)De Morgan's law
De Morgan's law moves a NOT through a bracket: break the bar, change the sign.
De Morgan's law is two facts that let you move a NOT through a bracket. They are the only Boolean algebra IGCSE needs.
| This | is the same as | |
|---|---|---|
| Rule 1 | NOT (A AND B) | (NOT A) OR (NOT B) |
| Rule 2 | NOT (A OR B) | (NOT A) AND (NOT B) |
Why they are worth knowing here:
- They explain why NAND and NOR turn up everywhere.
- A Level examines them by name.
Remember:Say it as: break the bar, change the sign.
NOT (A AND B) = (NOT A) OR (NOT B)
NOT (A OR B) = (NOT A) AND (NOT B)
WHY, in words:
"not both of them are on" is the same as "at least one is off"
"neither of them is on" is the same as "both of them are off"NAND on its own can build anything
NAND gates alone can build every other gate, so NAND is a universal gate.
Join both inputs of a NAND gate to the same wire. It now behaves as a NOT.
Once you have NOT, you can build the others:
AND: aNANDfollowed by aNOT.OR: use De Morgan. Invert both inputs, thenNANDthem.
This is why NAND is called a universal gate. It is also why a real chip can be manufactured out of one kind of part, repeated millions of times.
NOT A = A NAND A
A AND B = NOT (A NAND B)
= (A NAND B) NAND (A NAND B)
A OR B = (NOT A) NAND (NOT B) [De Morgan]
= (A NAND A) NAND (B NAND B)
So: one part, three gates, and from those three, everything else.How many rows, and in what order
The number of inputs fixes the number of rows, and the rows go in binary counting order.
Watch out:The commonest lost mark in this topic is a missing row.
The number of rows is fixed by the number of inputs:
| Inputs | Rows |
|---|---|
| two | 4 |
| three | 8 |
| four | 16 |
The rows must be written in binary counting order, starting at all zeros.
Remember:Write the whole empty table out before you fill anything in. Then you cannot lose a row.
n inputs -> 2^n rows
2 inputs (4 rows) 3 inputs (8 rows)
0 0 0 0 0
0 1 0 0 1
1 0 0 1 0
1 1 0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
A quick way to write them: the last column alternates 0 1 0 1 ...,
the one before it goes 0 0 1 1 0 0 1 1 ..., the one before that
0 0 0 0 1 1 1 1 ... Each column changes half as often as the one
to its right.AND| A | B | Output |
|---|---|---|
| 0 | 0 | |
| 0 | 1 | |
| 1 | 0 | |
| 1 | 1 |
KEY TERMS
CHECK YOURSELF
1.For which inputs does XOR output 1?
2.A NAND gate with both inputs set to 1 outputs:
3.A circuit has 3 inputs. How many rows does its truth table need?
4.A truth table has three rows where the output is 1. Using sum of products, how many AND terms will the expression have?
5.A row of a truth table reads R = 0, S = 1, T = 1, and the output is 1. What is the AND term for that row?
6.When you draw the circuit for Q = NOT (A OR (B AND C)), which gate do you draw LAST?
7.Why add a column for every gate when completing a truth table, instead of only the final output?
8.A two-input truth table has output 0 in exactly one row — the row where both inputs are 1. Which single gate is it?
9.How do you make a NAND gate behave as a NOT gate?
10.A question says SIMPLIFY the logic circuit. Is a correct sum-of-products expression enough for full marks?