← AS/A Level

CS · Chapter 4

Cambridge AS & A Level · Part 1 · Chapter 4

Logic Gates and Logic Circuits

How a TRUE/FALSE question becomes a logic expression, a circuit of gates and a truth table, and how to turn any one of those into the others. Every figure, task and exam question from the chapter is here, with live circuits to try each idea.

Guru Jazzy
Chapter 4 opener: binary digits flowing through a web of connections

🎯 Learning objectives

By the end of this chapter you should be able to:

  • use the symbols for the NOT, AND, OR, NAND, NOR and XOR gates
  • understand and define what each of these gates does
  • Construct the truth table for each gate
  • construct a logic circuit from a problem statement, a logic expression or a truth table
  • construct a truth table from a problem statement, a logic circuit or a logic expression
  • construct a logic expression from a problem statement, a logic circuit or a truth table

🗺️ One idea, four ways of writing it

The whole chapter is about one situation described in four interchangeable forms. Each later tab practises one of the conversions.

FormWhat it looks likeExample
Problem statementEveryday wordsTake an umbrella if it is raining or rain is forecast.
Logic expressionPropositions joined by Boolean operatorsX = A OR B
Logic circuitGate symbols joined by wiresAn OR gate with inputs A and B
Truth tableEvery input combination with its output00→0, 01→1, 10→1, 11→1

💬 4.01 Boolean logic and problem statements

Suppose someone asks whether Colombo is further north than Singapore. If you know a little geography, you answer yes or no. You could just as well say the statement is TRUE or FALSE: in logic, those are the only two possible values.

Logic proposition: a statement that is either TRUE or FALSE.

Real decisions usually depend on more than one proposition:

  • I will take an umbrella if it is raining or the forecast says rain.
  • The air-conditioning should run during working hours and when the temperature is above 25 °C.

Each of these is a problem statement: an informal description of an outcome. The words or and and are doing logical work, joining two propositions.

Problem statement: an informal definition of an outcome that depends on one logic proposition, or on a combination of two or more.

🧪 Spot the proposition

A logic proposition has to be something that is definitely TRUE or definitely FALSE at a given moment. Questions, commands and opinions are not propositions. Check yourself:

🎮 Proposition or not?

⚙️ 4.02 Boolean operators

The words that join propositions become Boolean operators, named after the mathematician George Boole. Three of them do all the work:

OperatorDefinition
A AND BTRUE if A is TRUE and B is TRUE
A OR BTRUE if A is TRUE or B is TRUE (or both)
NOT ATRUE if A is FALSE

Using them, the two problem statements from 4.01 can be written more formally:

Take_umbrella = TRUE IF (raining = TRUE) OR (rain_forecast = TRUE)

Aircon_on = TRUE IF (working_hours = TRUE) AND (temperature > 25)

Logic expression: logic propositions combined using Boolean operators; it may be set equal to a named outcome.

Any logic expression at all can be written with only AND, OR and NOT. Even so, three more operators are useful:

OperatorDefinitionThink of it as
A NAND BTRUE if A is FALSE or B is FALSENOT (A AND B)
A NOR BTRUE if A is FALSE and B is FALSENOT (A OR B)
A XOR BTRUE if exactly one of A and B is TRUE"one or the other, not both"

🛒 Worked Example 4.01 Problem statement → expression

A shopkeeper has new stock delivered at the end of every month. A delivery is also made early in two situations: when the stock of an item falls to its re-order level, or when a regular customer places an order for a large amount.

Step 1: name the propositions.

SymbolProposition
AIt is the end of the month
BThe re-order level has been reached
CThe order is from a regular customer
DThe order is for a large amount

Step 2: join them. Any one of three things triggers a delivery, so they are joined with OR. The third one needs both C and D, so it is bracketed with AND:

X = A OR B OR (C AND D)

✏️ Task 4.01

Task 4.01 A document may be copied if it is not covered by copyright. It may also be copied if it is covered by copyright but permission has been obtained. Write this as a logic expression.

Let A = the document is covered by copyright and B = permission has been obtained.

X = NOT A OR (A AND B)

Check the truth table below: X is 0 only when A = 1 and B = 0. That means the expression simplifies to NOT A OR B, but writing it the long way, straight from the statement, is fine.

🎮 Problem statement → expression

Read the situation and choose the expression that matches it exactly. Watch the brackets.

📊 4.03 Truth tables

A truth table lists every possible combination of input values and the output each one produces. In a truth table, 1 stands for TRUE and 0 for FALSE. Here is the table for A AND B:

Table 4.01 · the truth table for A AND B

ABA AND B
000
010
100
111

Only the last row has both inputs TRUE, so it is the only row with an output of 1.

Tip: fill in the input columns as binary numbers counting up: 00, 01, 10, 11 for two inputs; 000 to 111 for three. Then you can never miss or repeat a combination. n inputs always give 2ⁿ rows.

✏️ Task 4.02

Task 4.02 Construct the truth table for A OR B.
ABA OR B
000
011
101
111

Any row with at least one 1 gives 1. Only 00 gives 0.

🎮 Fill in the truth table

A new expression every time. Tap each output cell to set it to 0 or 1, then check. Work out the brackets first.

🔌 4.04 Logic circuits and logic gates

Inside a computer, a logic proposition is a signal that is either on (1) or off (0). A logic circuit combines these signals using components called logic gates, each one acting like a Boolean operator.

Logic gate: a component of a logic circuit whose operation matches that of a Boolean operator.

Every gate has its own symbol. The shape tells you which gate it is; the inputs come in on the left and the output leaves on the right. Here is the AND gate:

Figure 4.01 (redrawn) · the symbol for an AND gate

A gate can be built with more than two inputs, but in this course every gate has at most two.

🔣 All six gates Figure 4.02

Figure 4.02The six logic gate symbols with their truth tables: NOT, AND, OR, NAND, NOR and XOR
  • The NOT gate has only one input. Its output is the opposite of that input.
  • A NAND gate gives the same result as an AND gate followed by a NOT gate. The small circle (bubble) on its output means "invert".
  • A NOR gate gives the same result as an OR gate followed by a NOT gate.
  • XOR is the OR shape with an extra curved line at the back.
Tip: it is easy to mix up AND and OR. The AND gate has the neat D shape (think "AND has a D in it"). The OR gate is the curved, pointed one.

🔬 Lab: gate explorer

Choose a gate, then toggle its inputs. The lit wires carry 1, and the current row of the truth table lights up.

✏️ Task 4.03 and Extension Question 4.01

Task 4.03 Draw an AND gate with its output fed into a NOT gate. Show that the truth table matches the NAND gate.

Toggle both circuits: for every row the outputs match. P is the output of the AND gate.

Extension Question 4.01 Could a NOT gate on each input, followed by an AND gate, give the same result as NAND?

No. NOT A AND NOT B is 1 only when both inputs are 0. That is the NOR truth table. NAND is 1 for 00, 01 and 10. The two differ for inputs 01 and 10.

The rule that does work is NOT (A AND B) = NOT A OR NOT B. You will meet this again as De Morgan's law in Chapter 19.

❓ Question 4.01

Question 4.01 Without looking back, draw the symbol and write a definition for each of the six gates.
GateSymbolOutput is 1 when…
NOTTriangle with a bubble, one inputthe input is 0
ANDFlat back, D-shaped frontboth inputs are 1
ORCurved back, pointed frontat least one input is 1
NANDAND shape with an output bubbleat least one input is 0
NOROR shape with an output bubbleboth inputs are 0
XOROR shape with an extra curve at the backexactly one input is 1

🎮 Name that gate

Identify the gate from its symbol.

🎮 Which gate behaves like this?

Identify the gate from its truth table or its definition.

🏦 Worked Example 4.02 Statement → expression → circuit

A bank offers a special interest rate. To get it, a customer must have banked there for at least two years. They must also meet at least two of these three conditions: they are married, they are aged 25 or over, and at least one of their parents banks there.

Step 1: the propositions.

SymbolProposition
AA customer for two years or more
BMarried
CAged 25 or over
DA parent is a customer

Step 2: the expression. "Two of B, C and D" means B AND C, or B AND D, or C AND D. A is needed as well:

X = A AND (((B AND C) OR (B AND D)) OR (C AND D))

The extra brackets are there because each gate has only two inputs, so the three ORs have to be done one pair at a time.

Step 3: the circuit. Each AND or OR in the expression becomes one gate, so the circuit needs four AND gates and two OR gates.

Figure 4.03The logic circuit for the bank special-rate rule, with inputs A, B, C and D

Here it is live. P, Q and R are the three AND pairs; S and T are the two OR gates.

🔬 Lab: expression → circuit

Type any logic expression using up to four letters and the operators AND, OR, NOT, NAND, NOR, XOR and brackets. You will get its circuit and its truth table. NOT is applied first, then AND, then XOR, then OR, so use brackets if you mean something else.

🔍 Worked Example 4.03 Circuit → truth table

Find the truth table for this circuit:

Figure 4.04A three-input logic circuit whose truth table is to be found

Step 1: set up the table. Three inputs give eight rows. Leave a workspace between the inputs and the output for the values partway through the circuit:

InputsWorkspaceOutput
ABCMNPQX
000
… and so on to 111

Table 4.02 · the empty table with its workspace

Step 2: label the intermediate points. Each gate output gets a letter:

Figure 4.05The same circuit with the intermediate points labelled M, N, P and Q
  • M = A AND B
  • N = NOT B
  • P = NOT M
  • Q = N AND C
  • X = P AND Q

Step 3: fill in the columns from left to right. Each workspace column only needs columns already filled in. Toggle the inputs to watch the values flow, then compare with the finished table:

X is 1 only for inputs 001 and 101.

Check your table: C only reaches X through two AND gates, so whenever C = 0 the output must be 0. All four rows with C = 0 do give X = 0. Look for quick checks like this before you hand in.

🎮 Trace a mystery circuit

A new random circuit each time. Trace each row through the gates (write the workspace values on paper), then fill in the output column and check.

🔁 Truth table → logic expression

To write an expression from a truth table, use only the rows where the output is 1:

  1. For each of those rows, AND the inputs together, putting NOT in front of any input that is 0.
  2. OR all of those terms together.

Table 4.04 · a truth table to turn into an expression

ABCX
0000
0011
0100
0111
1001
1010
1100
1110

Rows 001, 011 and 100 give 1, so:

X = (NOT A AND NOT B AND C) OR (NOT A AND B AND C) OR (A AND NOT B AND NOT C)

This is correct but long. Chapter 19 shows how to simplify expressions like this one.

🔌 Logic circuit → logic expression

There are two ways to do this:

  • Build the truth table for the circuit (as in the Circuit → truth table tab), then use the rows with output 1 as above.
  • Or work backwards from the output, writing each gate as an operator with its two inputs in brackets. For Figure 4.05 this gives X = NOT (A AND B) AND (NOT B AND C).

✏️ Task 4.04

Task 4.04 An oven has three sensors. A = fan (1 = working). B = internal light (1 = working). C = thermometer (1 = temperature in range). A warning light should come on if the temperature is in range but the fan or the light (or both) has failed. Write the logic expression, draw the circuit and complete the truth table.

X = (NOT A OR NOT B) AND C

P is NOT A OR NOT B, which is the same as A NAND B. The light is on for inputs 001, 011 and 101.

🎮 Truth table → expression

Write any expression that gives this truth table. The answer is auto-marked by testing every row, so a simplified version counts too. Type AND, OR, NOT and brackets, with spaces between words.

🎮 Circuit → expression

Which expression describes this circuit? Read it backwards from X.

📌 Summary

  • A logic scenario can be described by a problem statement or by a logic expression.
  • A logic expression is made of logic propositions joined by Boolean operators.
  • A logic circuit is built from logic gates, and each gate works like one Boolean operator.
  • The outcome of a logic expression or logic circuit can be set out as a truth table.
  • A logic expression can be built from a truth table by using the rows that give an output of 1.

🪞 Reflection Point

Reflection Point: What do you think is the one central idea of this chapter?

That a problem statement, a logic expression, a logic circuit and a truth table are four ways of writing the same logic, and you can always get from any one of them to any other. The truth table is the common ground: if two versions give the same truth table, they are equivalent.

🃏 Key-term flashcards

Tap a card to flip it.

✅ Quick quiz

📝 Exam-style questions

Write your answer first, then open the model answer. These are my own mark-scheme-style answers, not official mark schemes. Where the answer is a circuit, it is live: toggle the inputs to check it.

Question 1 aThree logic gate symbols labelled Gate 1, Gate 2 and Gate 3

(i) Gate 1: OR. Gate 2: NAND. Gate 3: NOT.

(ii) Either table:

ABORNAND
0001
0111
1011
1110
Question 1 bA circuit of two AND gates and two OR gates with inputs A, B and C

(i) P = A AND B, Q = B AND C, R = P OR Q, X = R OR C:

ABCPQRX
0000000
0010001
0100000
0110111
1000000
1010001
1101011
1111111

(ii) The B AND C gate is redundant. Whenever its output is 1, C must be 1, and C already goes straight to the final OR gate, which makes X = 1 anyway. Removing the gate leaves X = (A AND B) OR C with the same truth table.

ABX
001
011
101
110

(i) A = the team wins match 1. B = the team wins match 2. C = the team has the higher total score.

(ii) "Wins one and loses the other" is exactly what XOR means:

X = (A AND B) OR ((A XOR B) AND C)

Also accepted: (A AND B) OR (A AND NOT B AND C) OR (NOT A AND B AND C).

(iii)

Question 3 A home heating system has a hot water tank and radiators. A management system receives three signals:
SignalValueCondition
A0Water flow in the radiators is too low
1Water flow in the radiators is within limits
B0Hot water tank temperature is too high
1Hot water tank temperature is within limits
C0Water level in the hot water tank is too low
1Water level in the hot water tank is within limits

Too low means C = 0 and too high means B = 0, so X = NOT B AND NOT C. A does not affect the output.

(i)

ABCX
0001
0010
0100
0110
1001
1010
1100
1110

(ii) B and C each go through a NOT gate, then into an AND gate. (A NOR gate on B and C would also do the job.)

B = 1, A = 0 and C = 0, so X = B AND NOT A AND NOT C. Only input 010 gives 1.

X = (A OR NOT B) OR (B AND NOT C)

P = A OR NOT B, Q = B AND NOT C:

ABCPQX
000101
001101
010011
011000
100101
101101
110111
111101

X is 0 only for input 011.

Question 4 cA circuit of three NOT gates, two AND gates and two OR gates with inputs A, B and C

Work backwards from X: the final AND gate takes NOT C and the output of an OR gate, which joins (NOT A AND B) with (NOT B OR C).

X = ((NOT A AND B) OR (NOT B OR C)) AND NOT C

Cambridge International AS & A Level Computer Science 9608, Paper 13 Q6, June 2015

X = (NOT B AND NOT S) OR (NOT P AND S)

Three NOT gates, two AND gates and one OR gate. In the circuit below the second AND gate takes S on top, which is the same thing.

J = NOT B AND NOT S, K = NOT P AND S:

BSPJKX
000101
001101
010011
011000
100000
101000
110011
111000

Cambridge International AS & A Level Computer Science 9608, Paper 12 Q1, November 2016

Guru Jazzy · Cambridge AS & A Level Computer Science · Chapter 4 Logic Gates and Logic Circuits · Figures from the Cambridge coursebook (Langfield & Duddell)