Boolean Logic
NOT, AND, OR and XOR, how to build and read a logic circuit diagram, and a reliable method for completing the truth table of a combined circuit without guessing.
The four gates
A logic gate is a physical circuit taking one or more binary inputs and producing one binary output according to a fixed rule.
NOT
Inverts its single input. Written as NOT A.
| A | Q |
|---|---|
| 0 | 1 |
| 1 | 0 |
AND
Output is 1 only when both inputs are 1. Written as A AND B.
| A | B | Q |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
OR
Output is 1 when at least one input is 1. Written as A OR B.
| A | B | Q |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
XOR
Exclusive OR. Output is 1 when the inputs are different. Written as A XOR B.
| A | B | Q |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
Both give 1 when one input is 1. Only OR also gives 1 when both are. Learn the bottom row and you have learned the difference.
Reading and drawing circuit diagrams
A logic circuit joins gates together, with the output of one becoming the input of the next.
To read a circuit, work from the inputs on the left towards the output on the right, naming the output of each gate as you go. Never try to see the whole thing at once.
For the circuit Q = (A AND B) OR (NOT C):
- A and B go into an AND gate. Call its output
X. - C goes into a NOT gate. Call its output
Y. - X and Y go into an OR gate, and its output is Q.
Writing the expression from the diagram is the same process in reverse, working outwards from the inputs and bracketing each gate's output before it feeds the next.
(A AND B) OR C and A AND (B OR C) are different circuits with different truth tables. If you are asked to write an expression from a diagram, the brackets are part of the answer.
- Two inputs, one AND gate, one NOT gate, one output.
- A = 1 and B = 0. AND needs both, so it gives 0.
- NOT flips it, so Q becomes 1.
- A = 1 and B = 1. AND gives 1, NOT flips it, Q is 0.
- Q = NOT (A AND B). That is a NAND gate, written out.
Truth tables for combined circuits
This is where marks are won and lost, and there is a method that removes the guesswork entirely.
Step 1: work out how many rows. Two inputs give 4 rows, three inputs give 8, four give 16. It is 2 to the power of the number of inputs.
Step 2: fill the input columns systematically. With three inputs, the right hand column alternates 0 1 0 1, the middle alternates in pairs 0 0 1 1, and the left in fours 0 0 0 0 1 1 1 1. That guarantees every combination appears exactly once.
Step 3: add a column for every intermediate gate output. This is the step most candidates skip and it is where the method marks live.
Step 4: fill each column completely before starting the next. Working across a row means holding three rules in your head at once. Working down a column means applying one rule sixteen times, which is far harder to get wrong.
For Q = (A AND B) OR (NOT C):
| A | B | C | A AND B | NOT C | Q |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 | 1 |
| 0 | 0 | 1 | 0 | 0 | 0 |
| 0 | 1 | 0 | 0 | 1 | 1 |
| 0 | 1 | 1 | 0 | 0 | 0 |
| 1 | 0 | 0 | 0 | 1 | 1 |
| 1 | 0 | 1 | 0 | 0 | 0 |
| 1 | 1 | 0 | 1 | 1 | 1 |
| 1 | 1 | 1 | 1 | 0 | 1 |
The examiner cannot award method marks for working that is not there. Leave every column you added on the page.
Logic gate simulator
Build a circuit from gates, wire it up, and see the truth table fill in as you go. This tool needs JavaScript, so turn it on to use it. Everything you need to answer the exam question is explained in the text above.
Key terms you must be able to define
- Logic gate
- A circuit that takes binary inputs and produces a binary output according to a fixed rule.
- NOT gate
- A gate with one input whose output is the opposite of that input.
- AND gate
- A gate whose output is 1 only when both inputs are 1.
- OR gate
- A gate whose output is 1 when at least one input is 1.
- XOR gate
- A gate whose output is 1 when its two inputs are different.
- Truth table
- A table listing the output of a circuit for every possible combination of inputs.
- Logic circuit
- Two or more gates joined together, with the output of one feeding the input of another.
- Boolean expression
- A written form of a logic circuit, using NOT, AND, OR and XOR with brackets.
Flashcards
Say the definition out loud before you flip the card. Retrieving it from memory is what builds recall, reading it again is not.
Reach the top grade on this topic
Logic questions are the most mechanical on the paper, so the marks go to whoever is most systematic.
Fill columns, not rows. One rule applied many times beats many rules applied once. It is faster and it is far more accurate.
Always add intermediate columns. They are worth method marks in their own right, and they make the final column almost impossible to get wrong.
Check two rows against the circuit at the end. Pick the all zeros row and the all ones row and trace them through the diagram. If both match, the rest almost certainly does.
When comparing two circuits, put the truth tables side by side. "The output columns are identical for every combination of inputs, so the circuits are equivalent" is the sentence a mark scheme is looking for.
Mistakes that cost marks here
- Confusing OR with XOR. They differ only when both inputs are 1.
- Getting the wrong number of rows. Three inputs need eight rows, not six.
- Filling the input columns unsystematically, so a combination is missed or repeated.
- Rubbing out intermediate columns before handing in, which throws away method marks.
- Ignoring brackets when writing an expression from a diagram.
Boolean algebra was published by George Boole in 1854 as a way of expressing logical reasoning mathematically. It had no practical application at all until Claude Shannon connected it to electrical switching circuits, eighty five years later.
Knowledge check
Exam-style questions
Five written questions in the style of the real paper. Write a full answer, then let the marker check it against the mark scheme.
- LUses four rows covering all combinations of A and B
- LIncludes a column for NOT A
- LGives Q as 1 only when A is 0 and B is 1
- LGives Q as 0 in the other three rows
With A and B as inputs the table has four rows. Adding a column for NOT A gives 1, 1, 0, 0 as A runs 0, 0, 1, 1. Q is that column ANDed with B, so Q is 0 when A is 0 and B is 0, Q is 1 when A is 0 and B is 1, Q is 0 when A is 1 and B is 0, and Q is 0 when A is 1 and B is 1. The output is therefore 1 in exactly one row, the one where A is 0 and B is 1.
- LAn OR gate outputs 1 when at least one input is 1
- LAn XOR gate outputs 1 only when the inputs are different, so 0 when both are 1
An OR gate gives an output of 1 whenever at least one of its inputs is 1, including when both are. An XOR gate gives an output of 1 only when its two inputs are different, so when both inputs are 1 its output is 0. The two gates therefore agree on three of the four rows of the truth table and differ only on the last.
- LWrites the AND operation in brackets
- LApplies XOR with C to that output
- LStates 8 rows
The AND gate acts first on A and B, so its output is written as A AND B and must be bracketed because it becomes a single input to the next gate. That output is then combined with C by the XOR gate, giving Q equals (A AND B) XOR C. With three inputs there are 2 to the power 3 combinations, so the truth table would have 8 rows.
- LEach column applies one simple rule rather than several at once
- LThis makes errors far less likely
- LThe working is creditworthy, so method marks can be awarded even if the final column is wrong
Adding a column for each gate turns the problem into a series of single steps, so at each column you are applying one gate's rule repeatedly rather than holding two or three rules in your head while working across a row. That is both faster and considerably less error prone. It also matters for marks: the intermediate columns are the visible working, so an examiner can award method marks for a correct approach even if a slip appears in the final output column. Working that has been rubbed out cannot earn anything.