Boolean Logic
AND, OR and NOT gates, drawing and reading logic diagrams, and completing truth tables for combined circuits without making arithmetic slips.
The three gates
NOT
NOT inverts the input. Output is the opposite of the input.
| A | NOT A |
|---|---|
| 0 | 1 |
| 1 | 0 |
Symbol: a triangle with a small circle on the output.
AND
AND outputs 1 only when both inputs are 1.
| A | B | A AND B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
Symbol: a D shape.
Think of two switches in series. The light only comes on if both are closed.
OR
OR outputs 1 when at least one input is 1.
| A | B | A OR B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
Symbol: a curved shield shape.
Think of two switches in parallel. The light comes on if either one is closed.
AND needs both. OR needs at least one. NOT flips it.
Truth tables for combined circuits
When gates are combined, build the truth table one column at a time.
Method
- List every input combination. With 2 inputs there are 4 rows, with 3 inputs there are 8 rows.
- Add a column for each intermediate output, not just the final one.
- Work through the circuit in the order the signals flow.
Getting the input combinations in a reliable order matters. For three inputs, count in binary from 000 to 111:
000, 001, 010, 011, 100, 101, 110, 111
Worked example
Complete a truth table 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 |
Notice the intermediate columns. Without them, the last two rows are very easy to get wrong.
Even if the final column contains an error, correct intermediate columns show your working and usually score.
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.
- 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.
Reading and writing logic diagrams
From a diagram to an expression
Work from the inputs towards the output, naming each intermediate signal as you go.
If A and B both go into an AND gate, and that output goes into an OR gate with C, then:
Q = (A AND B) OR C
From an expression to a diagram
Work inside out, exactly like brackets in maths.
For Q = NOT (A OR B):
- Draw an OR gate with inputs A and B.
- Feed its output into a NOT gate.
- The NOT gate's output is Q.
Order of operations
Brackets first, then NOT, then AND, then OR.
A OR B AND C means A OR (B AND C).
Even where the precedence rules make them unnecessary, brackets remove all ambiguity and cost you nothing.
Applying logic to real situations
Exam questions often describe a real system and ask for the expression.
Example 1
An alarm sounds if the door sensor is triggered AND the system is armed.
Alarm = Door AND Armed
Example 2
A greenhouse fan turns on if the temperature is too high OR the humidity is too high, but only when the system is switched on.
Fan = (Temp OR Humidity) AND SystemOn
Example 3
A car will only start if the key is present, the brake is pressed, and the bonnet is NOT open.
Start = Key AND Brake AND (NOT Bonnet)
Reading the wording
| Wording | Gate |
|---|---|
| both, and, as well as | AND |
| either, or, at least one | OR |
| not, unless, without | NOT |
Underline every and, or and not in the description, then build the expression around them. The wording almost always maps directly.
Key terms you must be able to define
- Boolean logic
- A system of logic in which every value is either true or false, represented as 1 or 0.
- AND gate
- A logic gate whose output is 1 only when all of its inputs are 1.
- OR gate
- A logic gate whose output is 1 when at least one of its inputs is 1.
- NOT gate
- A logic gate that inverts its input, also called an inverter.
- Truth table
- A table showing the output of a logic expression for every possible combination of inputs.
- Logic diagram
- A drawing showing how logic gates are connected together.
- Logic gate
- An electronic component that performs a Boolean operation on one or more inputs.
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
Everything on this topic is achievable, so the goal is to get every mark, every time.
Never do a truth table in your head. Write out every row and every intermediate column. It costs thirty seconds and prevents the errors that lose whole questions.
Get the input combinations right. Count in binary. For three inputs that is 000 through to 111, which gives eight rows in a reliable order with nothing missed.
Use brackets in every expression you write. They cost nothing and remove all ambiguity from your answer.
For scenario questions, underline the logic words in the description first. Every and, or and not maps almost directly onto a gate.
- Complete an eight row truth table with two intermediate columns in under four minutes
- Convert any logic diagram into an expression, and any expression into a diagram
- Write a Boolean expression from a written description of a real system
- Recall all three gate symbols and all three truth tables from memory
Mistakes that cost marks here
- Missing input combinations in a truth table. Two inputs give four rows, three inputs give eight.
- Skipping intermediate columns, then making an error that could not be spotted or credited.
- Confusing the AND and OR truth tables, particularly the row where both inputs are 1.
- Applying NOT to the wrong part of an expression because brackets were left out.
- Reading 'either' as AND. Either means OR.
Boolean algebra was published by George Boole in 1854 as pure mathematics with no practical use in sight. Eighty four years later Claude Shannon realised it described electrical switching circuits exactly, and the entire digital age followed from that connection.
Knowledge check
1 AND 0?0 OR 1?NOT (1 AND 1)?Q = (A OR B) AND NOT C, what is Q when A=0, B=1, C=0?A OR B AND C, which operation is carried out first?NOT 0 AND NOT 1?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.
- LIncludes all four input combinations for A and B
- LIncludes an intermediate column for NOT B
- LQ is 1 only when A is 1 and B is 0
- LQ is 0 for all other combinations
With A and B as inputs there are four combinations. When A is 0 and B is 0, NOT B is 1 and Q is 0 AND 1 which is 0. When A is 0 and B is 1, NOT B is 0 and Q is 0. When A is 1 and B is 0, NOT B is 1 and Q is 1 AND 1 which is 1. When A is 1 and B is 1, NOT B is 0 and Q is 1 AND 0 which is 0. So Q is 1 only in the single case where A is 1 and B is 0, and 0 in every other case.
- LUses AND to combine the two conditions
- LCorrect expression such as Light = Movement AND Dark
Light = Movement AND Dark. Both conditions must be satisfied for the light to switch on, so the two inputs are combined with an AND gate: the movement sensor must be triggered and it must also be dark.
- LAn AND gate outputs 1 only when all inputs are 1
- LAn OR gate outputs 1 when at least one input is 1
- LRefers to the difference in the case where only one input is 1
An AND gate produces an output of 1 only when every one of its inputs is 1, so with two inputs it outputs 1 in just one of the four possible cases. An OR gate produces an output of 1 whenever at least one of its inputs is 1, so with two inputs it outputs 1 in three of the four cases. The gates therefore differ in exactly those cases where only one input is 1: an AND gate outputs 0 while an OR gate outputs 1. They agree only when both inputs are 0, giving 0, and when both are 1, giving 1.
- LCorrectly groups the pedal and button with OR
- LCombines that result with the guard using AND
- LFull expression such as Operate = Guard AND (Pedal OR Button)
- LStates the output is 0, because the guard is open so the AND cannot be satisfied
Operate = Guard AND (Pedal OR Button). The pedal and the hand button are alternatives, so they are combined with an OR gate, and the result of that must be combined with the guard using AND because the guard must be closed in every case. If the guard is open then Guard is 0, and regardless of whether the pedal or the button is pressed the OR gate output is ANDed with 0, so the final output is 0 and the machine will not operate. This is the correct and intended safety behaviour.
- LLists all eight combinations of A, B and C
- LIncludes an intermediate column for A OR B
- LIncludes an intermediate column for NOT C
- LQ is 0 for every row where C is 1
- LQ is 0 when A and B are both 0
- LQ is 1 for the rows 010, 100 and 110
There are eight input combinations, counting in binary from 000 to 111. The intermediate column A OR B is 0 only when both A and B are 0, and 1 otherwise. The intermediate column NOT C is 1 whenever C is 0 and 0 whenever C is 1. Q is the AND of those two columns, so Q is 1 only when at least one of A and B is 1 and C is 0. That gives Q equal to 1 for the input combinations 010, 100 and 110, and Q equal to 0 for the other five combinations, namely 000, 001, 011, 101 and 111.