Skip to content

0478 · Unit 10 · Paper 2: Algorithms, programming and logic

Boolean logic.

0478 · Unit 10 · Boolean logic
Revisionbyexamplicity

The six logic gates

§10 · Boolean logic

Inside a computer, every decision is made by circuits that work with signals that are either on (1) or off (0). Each one is a logic gate: it takes one or two binary inputs (0 = off / false, 1 = on / true) and gives one binary output.

Every circuit you will meet is built from these six. Know each one's symbol, truth table and expression, with the gate names written as words. OR gives 1 when both inputs are 1; XOR does not.

NOT

AX
X = NOT A
AX
01
10

Output is the opposite of the input. One input only.

AND

ABX
X = A AND B
ABX
000
010
100
111

Output is 1 only if both inputs are 1.

OR

ABX
X = A OR B
ABX
000
011
101
111

Output is 1 if at least one input is 1 (including both).

NAND

ABX
X = A NAND B
ABX
001
011
101
110

NOT AND: output is 0 only if both inputs are 1.

NOR

ABX
X = A NOR B
ABX
001
010
100
110

NOT OR: output is 1 only if both inputs are 0.

XOR (EOR)

ABX
X = A XOR B
ABX
000
011
101
110

Exclusive OR: output is 1 only if the inputs are different.

Shaded rows: the inputs that give an output of 1.

Your turn

1 A = 1 and B = 0. Give the output of AND, OR, NAND and XOR.

2 Which two gates give 1 when both inputs are 0?

3 Which gate gives 1 only when both inputs are 0?

  1. 1
    AND 0, OR 1, NAND 1, XOR 1
  2. 2
    NAND and NOR
  3. 3
    NOR (NOT OR)
Tick what you can do now
Practise with m26/22 Q7(a); s26/22 Q8(a); w24/23 Q3 (older paper: match gate symbols); s25/22 Q8(a) (older paper: draw XOR and its table); w25/21 Q4(d) (older paper: draw NAND and its table)
1 / 7
0478 · Unit 10 · Boolean logic
Revisionbyexamplicity

Logic conventions: symbols, rules and words

§10 · Boolean logic

A circuit drawing is only useful if everyone who reads it sees the same circuit. Draw each gate with its exact shape, and turn each joining word in a statement into its operator.

Drawing the symbols

Several shapes differ only in a small detail, so draw each gate so that it cannot be confused with the others.

AND

Flat back, round front.

OR

Curved back, pointed front.

NAND · NOR

AND or OR with a small circle on the output: the circle means NOT.

XOR

OR with an extra curved line across the inputs.

Rules for drawn circuits

Right gates can still make a wrong circuit if two wires look joined or a gate gets three inputs. Three rules prevent that:

Two inputs per gate

Every drawn gate except NOT has two inputs. Three conditions all needed → (A AND B) AND C: chain two AND gates.

Junction dots

Draw each input once and branch it at a dot. Wires that cross without a dot are not connected.

Do not simplify

Draw the expression as given: NOT (A AND B) is an AND gate then a NOT gate, not one NAND gate.

Turn the words into operators

Most problems describe the logic in words, not symbols. Find the joining words and write the operator each one means.

The statement says…UseExample
both … and …ANDthe card and the PIN are valid → A AND B
either … or … (or both)ORthe button is pressed or the sensor is triggered → A OR B
opposite to the defined 1 stateNOTthe door is not locked → NOT L
only one of … (not both)XORexactly one switch is on → A XOR B
not both … and …NANDthe alarm sounds unless both are safe → A NAND B
neither … nor …NORneither window nor door is open → W NOR D
Your turn

1 S = 1 when a switch is on; D = 1 when a door is open. Write an expression for: the lamp is on when the switch is on and the door is not open.

2 Write an expression for: the buzzer sounds when neither P nor Q is 1.

3 How many gates do you draw for NOT (A OR B)?

  1. 1
    X = S AND (NOT D)
  2. 2
    X = P NOR Q
  3. 3
    2: an OR gate, then a NOT gate (do not swap them for one NOR gate)
Tick what you can do now
Practise with m26/22 Q7(a); s26/22 Q8(a); s26/23 Q7(a); s24/22 Q8(a) (older paper: words and input-state mapping)
2 / 7
0478 · Unit 10 · Boolean logic
Revisionbyexamplicity

From an expression to a circuit and a truth table

§10 · Boolean logic

An expression already tells you how to build its circuit, if you read it from the inside out. Draw one gate for each operator, starting inside the brackets. Then fill in the truth table one column at a time.

ABCA NAND BPjunction dotB NOR CQXP XOR Q
ABCA NAND BPB NOR CQXP XOR Q

Draw it, one gate per operator

1
Find the gates inside each bracket: A NAND B and B NOR C.
2
B is used by both gates: draw one B line that branches, with a junction dot.
3
Join the two bracket outputs (P and Q) with the operator between them: XOR.
4
Check: 3 operators → 3 gates, each with at most two inputs.

The circuit shows which gates; the truth table shows what they do for every input. Give each bracket its own column, so each step can be checked on its own.

Truth table with working columns

ABCPQX
000110
001101
010101
011101
100110
101101
110000
111000

Fill it in column by column

  • List A B C in binary counting order, 000 to 111: 2³ = 8 rows.
  • Work out each bracket first, in its own column (P, Q).
  • Then combine the working columns: X = P XOR Q.
  • Use the P and Q from the same row; never mix rows.

Check contrasting rows

  • A/B/C = 0/0/0: NAND gives P = 1 and NOR gives Q = 1, so XOR gives X = 0.
  • A/B/C = 1/0/1: P = 1 and Q = 0, so X = 1.
  • XOR gives 1 only when P and Q differ.
Your turn

1 For X = (A AND B) OR (NOT C), how many gates does the circuit need?

2 Which gate gives the output X?

3 Complete the X column of its truth table, rows 000 to 111.

  1. 1
    3: AND, NOT, OR
  2. 2
    OR
  3. 3
    X = 1 0 1 0 1 0 1 1 (work out A AND B and NOT C first, then OR them)

A condition that A is not 1 is true when A = 0. Write it as NOT A.

Tick what you can do now
Practise with m26/22 Q7(a), Q7(b); s26/22 Q8(a), Q8(b); s26/23 Q7(a), Q7(b)
3 / 7
0478 · Unit 10 · Boolean logic
Revisionbyexamplicity

From a circuit to an expression

§10 · Boolean logic

A circuit can look tangled from the inputs, but it has only one output, so start there. Read the circuit from the output backwards: write the last gate, then replace each of its inputs with the part of the circuit that feeds it, in brackets.

ABCYPQY = P OR QP = A AND (NOT B)Q = NOT (B XOR C)
ABCYPQY = P OR QP = A AND (NOT B)Q = NOT (B XOR C)

Each card names one gate, working from Y back towards the inputs, and writes the part of the expression that gate gives.

1Last gate

The gate that gives Y is OR, fed by P and Q.

Y = P OR Q
2Wire P

An AND gate fed by A and NOT B.

P = A AND (NOT B)
3Wire Q

A NOT gate fed by an XOR of B and C.

Q = NOT (B XOR C)
4Substitute

Put each wire's part in brackets in place of P and Q.

Y = (A AND (NOT B)) OR (NOT (B XOR C))

A truth table proves the expression describes the circuit. Fill P and Q for every row first; Y then needs only the OR gate.

Truth table from the circuit

ABCPQY
000011
001000
010000
011011
100111
101101
110000
111011

Label every wire

Write the value of each intermediate wire (P, Q) for each row before you work out the output. Brackets in the expression match the gates in the circuit.

Keep each gate

The NOT after the XOR stays as two gates: write NOT (B XOR C). B branches at the junction dot, so it appears twice in the expression.

Bracket the whole input to NOT

NOT (B XOR C) flips the XOR's output. (NOT B) XOR C puts the NOT on a different wire: a different circuit.

Check your answer

Count the gates in the circuit (5) and the operators in your expression (NOT, AND, XOR, NOT, OR = 5). They must match.

Your turn
ABCX

1 Write the expression for this circuit.

2 Find X when A = 0, B = 0 and C = 1.

3 How many of the 8 input rows give X = 1?

  1. 1
    X = (A NOR B) AND (NOT C) (3 gates, 3 operators)
  2. 2
    0: A NOR B = 1, but NOT C = 0, so AND gives 0
  3. 3
    1 row: A = 0, B = 0, C = 0
Tick what you can do now
Practise with s26/21 Q8(a), Q8(b)
4 / 7
0478 · Unit 10 · Boolean logic
Revisionbyexamplicity

From a truth table to an expression and a circuit

§10 · Boolean logic

Sometimes all you are given is what a circuit must do: its truth table. You can work backwards from it, from the output column to an expression, then from the expression to a circuit.

Write the expression from the truth table

1 · Check for a single gate

Compare the output column with the six gates. If it matches one, that gate is a correct answer.

2 · Otherwise, use the rows where X = 1

Write one term per row: AND the inputs together, using NOT for an input that is 0. Then join the terms with OR.

X is 1 in two rows, 00 and 11, and the column matches none of the six gates, so write one term for each shaded row.

ABX
001
010
100
111
Row with X = 1Term
A = 0, B = 0(NOT A) AND (NOT B)
A = 1, B = 1A AND B

Draw the circuit from the expression

Each term becomes an AND gate, labelled in its own colour as in the table, and the OR gate joins the two.

ABX(NOT A) AND (NOT B)A AND B
ABX(NOT A) AND (NOT B)A AND B

Check it

Work out X for every row using your circuit. Every row must match. If a question gives you an expression or a circuit, keep its gates: do not redesign it.

Your turn

Table 1: which single gate is it? Tables 2 and 3: write an expression for X.

1

ABX
000
011
101
110

2

ABX
000
010
101
110

3

ABX
001
010
101
110
  1. 1
    XOR: 1 only when the inputs differ
  2. 2
    one row with X = 1 (A = 1, B = 0): X = A AND (NOT B)
  3. 3
    two rows with X = 1 (00 and 10): X = ((NOT A) AND (NOT B)) OR (A AND (NOT B)). NOT B alone gives the same table: any expression that matches every row is correct.
Tick what you can do now
Practise with m21/12 Q5(a) (older paper: identify a single gate from its truth table)
5 / 7
0478 · Unit 10 · Boolean logic
Revisionbyexamplicity

Three-input truth tables

§10 · Boolean logic

The method for two inputs works for three, with one catch. A row where X = 1 now has three inputs to join, and every gate takes only two, so each term needs two AND gates.

A three-input example

X is 1 in two rows, so there are two terms. Each one ANDs all three inputs, with a NOT on any input that is 0 in its row.

ABCX
0000
0010
0100
0111
1000
1010
1101
1110

Each highlighted row gives one term:

Row with X = 1Term (two-input gates)
A = 0, B = 1, C = 1((NOT A) AND B) AND C
A = 1, B = 1, C = 0(A AND B) AND (NOT C)

Draw it with two-input gates

Each coloured label sits on the AND gate that finishes its term. Trace back from it to find the first AND gate and the NOT it needs.

ABCX((NOT A) AND B) AND C(A AND B) AND (NOT C)
ABCX((NOT A) AND B) AND C(A AND B) AND (NOT C)

Two AND gates per term

A row such as A = 0, B = 1, C = 1 needs two AND gates: ((NOT A) AND B) AND C. The OR gate then joins the two terms.

Your turn

1 How many rows does a truth table with three inputs have?

2 Write the term for the row A = 1, B = 0, C = 1, using two-input gates.

3 X = 1 only in rows 001 and 111. Write an expression for X.

  1. 1
    2³ = 8 rows, 000 to 111
  2. 2
    (A AND (NOT B)) AND C
  3. 3
    X = (((NOT A) AND (NOT B)) AND C) OR ((A AND B) AND C) (7 gates: 2 NOT, 4 AND, 1 OR)
Tick what you can do now
Practise with w23/23 Q6(d) (older paper: draw a three-input expression with two-input gates)
6 / 7
0478 · Unit 10 · Boolean logic
Revisionbyexamplicity

From a problem statement to logic

§10 · Boolean logic

Real problems arrive as a description of a system, not as logic. Work from the defined input states (what 0 and 1 mean), not from one word alone. A greenhouse fan switches on in two ways: high humidity, or high temperature with the window closed.

1 · Write down what 0 and 1 mean for each input

Input0 state1 state
Ttemperature not too hightemperature too high
Wwindow closedwindow open
Hhumidity not highhumidity high

2 · Turn each condition into logic, then join them

Each condition in the description becomes one bracket; the last row says how the brackets join.

Condition that switches the fan onLogic relationship
Temperature too high and window closedT = 1 with W = 0: T AND (NOT W)
Humidity highH = 1 independently of temperature and window
Either condition is sufficient, including bothCombine the two conditions with OR

Play one situation through the circuit: T = 1, W = 0, H = 0. Each gate's output appears beside it, and the blue row of the truth table is the same situation.

TWH100X111fan on
TWH100X111fan on

Read the table

  • H = 1 → the fan is on, whatever T and W are.
  • H = 0 → the fan is on only when T = 1 and W = 0.

Truth table

TWHX
0000
0011
0100
0111
1001
1011
1100
1111

Blue row: the situation played in the circuit.

Check what 1 means before you use NOT

  • Here W = 1 means open, so “window closed” is NOT W.
  • If W = 1 had meant closed, you would use W itself, with no NOT.
Your turn

1 An alarm X sounds when the system is armed and the door is open, or when the panic button is pressed. A = 1 means armed; D = 1 means the door is closed; P = 1 means the button is pressed. Write the expression.

2 Find X when A = 1, D = 1 and P = 0.

3 How many of the 8 rows give X = 1?

  1. 1
    X = (A AND (NOT D)) OR P: the door is open when D = 0, so use NOT D
  2. 2
    0: the door is closed and the button is not pressed
  3. 3
    5: the 4 rows with P = 1, plus A = 1, D = 0, P = 0
Tick what you can do now
Practise with s24/22 Q8(a), Q8(b) (older paper: state-to-expression and table); s25/22 Q8(b) (older paper: problem-state circuit); w25/21 Q4(c) (older paper: problem-state expression)
7 / 7