A1.2.3 · Data representation and computer logic
Logic gates
By the end you can
Describe the AND, OR, NOT, NAND, NOR, XOR and XNOR gates, their symbols and truth tables, and how gates make decisions, add numbers and store bits inside a computer.
Everything a CPU does, from adding numbers to comparing passwords, is built from a handful of tiny circuits called . Each gate takes one or two binary inputs and gives one binary output by a fixed rule. They are made of transistors acting as switches, and a modern processor contains billions of them.
Gates work with Boolean values: 1 means true, 0 means false. So “A AND B” is true only if A is true and B is true, just as in English.
The seven gates
AND
output 0
OR
output 1
NOT
output 0
NAND
output 1
NOR
output 0
XOR
output 1
XNOR
output 0
Every gate's truth table#
A lists every possible input and the output for each. With two inputs there are four rows, in counting order: 00, 01, 10, 11. These seven are worth learning by heart.
| Gate | A B = 00 | 01 | 10 | 11 | Rule |
|---|---|---|---|---|---|
| AND | 0 | 0 | 0 | 1 | Output 1 only if both inputs are 1. |
| OR | 0 | 1 | 1 | 1 | Output 1 if at least one input is 1. |
| NOT | A = 0 → 1 · A = 1 → 0 | One input. Output the opposite. | |||
| NAND | 1 | 1 | 1 | 0 | NOT AND: output 0 only if both inputs are 1. |
| NOR | 1 | 0 | 0 | 0 | NOT OR: output 1 only if both inputs are 0. |
| XOR | 0 | 1 | 1 | 0 | Exclusive OR: output 1 if the inputs are different. |
| XNOR | 1 | 0 | 0 | 1 | Output 1 if the inputs are the same. |
Ways of writing them#
Textbooks and exams write the same gates in several notations. You should recognise all of them; in your own answers, words (AND, OR, NOT) are always clear.
| AND | A AND B · A·B · A ∧ B |
|---|---|
| OR | A OR B · A + B · A ∨ B |
| NOT | NOT A · Ā · ¬A |
| NAND | A NAND B · NOT (A·B) |
| NOR | A NOR B · NOT (A + B) |
| XOR | A XOR B · A ⊕ B |
| XNOR | A XNOR B · NOT (A ⊕ B) |
Where they show up#
AND
A machine press that only runs while both of the operator’s hands are on its two buttons.
OR
An interior light that comes on if either car door is open.
NOT
A street light that is on when the light sensor says it is NOT daytime.
NAND
A warning light that stays on unless both safety guards are closed. NAND is also a universal gate: any circuit can be built from NANDs alone, which is why chips use so many.
NOR
A "ready" light that is on only when neither of two error signals is present. Also universal.
XOR
Adding two bits (the sum bit of an adder), and a light controlled from both ends of a staircase.
XNOR
Checking whether two bits are equal. A row of XNORs, one per bit, tells the ALU whether two numbers are equal (a comparator).
What gates do inside a computer#
Gates are not just a topic for exams: every part of the CPU in A1.1 is built from them. They do three jobs.
1. Making decisions
Every condition in a program (if score > 50 and not late) ends up as gates: the ALU compares values, and AND, OR and NOT combine the results into one true or false that decides which instruction runs next. Control systems work the same way: a fire alarm ORs its smoke, heat and gas sensors, so any one of them sets it off.
2. Doing arithmetic
The ALU adds with gates. Adding two single bits gives a sum bit and a carry bit, and the truth table shows exactly which gates produce them: the sum is 1 when the bits differ (XOR) and the carry is 1 only when both are 1 (AND). That pair of gates is a .
| A | B | Carry (A AND B) | Sum (A XOR B) | In denary |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 + 0 = 0 |
| 0 | 1 | 0 | 1 | 0 + 1 = 1 |
| 1 | 0 | 0 | 1 | 1 + 0 = 1 |
| 1 | 1 | 1 | 0 | 1 + 1 = 2 |
Sum
Carry
A half adder can only add two bits. To add whole numbers, each column also has to take in the carry from the column to its right, so it needs three inputs. That circuit, made from two half adders and an OR gate, is a . Chain eight of them, each passing its carry to the next, and you can add two bytes. Subtraction reuses the same adder, by adding the two's complement (A1.2.2).
3. Storing bits
A gate on its own forgets: its output changes as soon as its inputs do. But connect two gates so that each one's output feeds back into the other's input, and the pair settles into one of two stable states and stays there. That circuit is a latch or : it holds one bit until a signal tells it to change. A register is a row of flip-flops (64 of them for a 64-bit register), and the cache on the CPU chip is built from similar cells. So the CPU's registers, its arithmetic and its decisions are all logic gates.
Joining gates into circuits, describing those circuits with expressions and truth tables, and making them smaller, is what the next two sections are about.
Check yourself
Logic gates and adders
Quick questions, made fresh every time and marked here. Do a few until they feel easy.
Exam practice
Paper 1-style questions
7 questions · 15 marks
Write your answer as you would in the exam, then show the mark points and tick each one your answer made. These are our own questions in the style of the exam, not past-paper questions.
1.Construct the truth table for A XOR B.
[2]Construct: Draw or write it out (a table, a diagram, a program).
2.State the output of a NOR gate when both inputs are 0.
[1]State: Give a short answer, no explanation needed.
3.Distinguish between an OR gate and an XOR gate.
[2]Distinguish: Make the differences between two things clear.
4.Outline why NAND gates are described as universal gates.
[2]Outline: A brief account: the main points, without much detail.
5.Explain how logic gates are used to add two single binary digits.
[4]Explain: Give reasons: say what happens AND why, or how one thing causes another.
6.Outline how logic gates are used to store data in a register.
[2]Outline: A brief account: the main points, without much detail.
7.A car’s seat-belt warning light should be on when the driver’s seat is occupied and the belt is not fastened. Suggest a combination of gates for this, with a reason.
[2]Suggest: Put forward a sensible answer for the situation given, with a reason. There may be several good answers.
Past papers
Old exam questions on this topic
From HL Paper 1, May 2014 to November 2025. These papers were set on the previous syllabus, so the wording may differ from today's exam, but the topic is the same. Find the questions and markschemes in your school's past-paper pack.
| Paper | Question | Marks | About |
|---|---|---|---|
| May 2024 TZ1 | 13(a) | 1 | Definition of NOR |
| November 2023 | 2 | 1 | Definition of NAND |
| November 2022 | 3 | 2 | Definition of XOR |
In a nutshell
- A logic gate takes binary inputs (1 = true, 0 = false) and gives one output by a fixed rule.
- AND: 1 only if both are 1. OR: 1 if either is 1. NOT: the opposite of its single input.
- NAND and NOR are AND and OR followed by NOT. Each is universal: any circuit can be built from it alone.
- XOR: 1 if the inputs differ. XNOR: 1 if they are the same.
- Each gate has a standard symbol; a small circle (bubble) on the output means NOT.
- Learn each gate’s truth table: questions often ask you to complete one.
- Inside the CPU, gates make decisions, do arithmetic (a half adder: sum = A XOR B, carry = A AND B; full adders chain to add bytes) and store bits (flip-flops form registers).
