Study Guide

Designing Logic Circuits

Turning a problem into a working logic circuit: choosing the inputs and gates from a description, writing the expression, drawing the circuit, working backwards from a truth table, and testing a design to find its mistakes.

Lesson 2.4 Boolean Logic

For: Cambridge IGCSE Computer Science (ages 14 to 16), after Lessons 1 to 3; useful for AS level revision

Stage: Think

What is the problem asking?

So far you have been given a logic circuit and worked out what it does. Now it is the other way round: you are told what a circuit must do, and you design it. Every design starts by reading the description for its inputs.

A school greenhouse has a sprinkler. It should water the plants when the soil is dry and it is not raining, or when the gardener switches it on by hand. The situation is fictional.

Think it through

What are the inputs, and which words in the description tell you how they combine?

Show what happens

Three inputs: soil dry (A), raining (B) and manual switch on (C). “And” joins soil dry with not raining; “not” turns raining round; “or” adds the manual switch.

Descriptions do not always use the words AND, OR and NOT. “While” and “but” usually mean AND; “unless” means AND NOT (“the light comes on when someone moves, unless it is daytime”: movement AND NOT daytime); “either … or” may mean OR or XOR, so read whether both together are allowed.

Stage: Apply

From a description to an expression

Before drawing anything, write the description as a logic expression: each condition becomes an input or a gate, and brackets keep together what the description keeps together.

Apply it

Using A (soil dry), B (raining) and C (manual switch on), which expression describes the sprinkler?
Show the answer

Answer: C. Q = (A AND NOT B) OR C

NOT goes on the input it describes, and brackets keep “dry and not raining” together before the OR.

A school corridor light comes on (Q) when someone moves (A) or a door opens (B), unless it is daytime (C). The situation is fictional.

  1. Find the inputs. Movement, the door and daytime are yes-or-no facts the light can detect: A, B and C. The light is the output, Q.
  2. Find the joining words. “Or” joins movement and the door. “Unless” means AND NOT, and it applies to the whole of “someone moves or a door opens”.
  3. Bracket what belongs together. A OR B must be worked out before the AND NOT, so it goes in brackets: Q = (A OR B) AND NOT C.
  4. Check one row. Someone moves in daytime: A = 1, B = 0, C = 1. A OR B is 1, NOT C is 0, so Q = 0, and the light stays off, as the description says.

Change one fact, C to 0 (it is dark): NOT C becomes 1, so Q = 1 and the light comes on.

Think it through

A school laptop charges (Q) when it is plugged in (A) and its battery is not full (B). Write the expression.

Show what happens

Q = A AND NOT B.

Stage: Experiment

From an expression to a circuit

Think it through

You are drawing the circuit for Q = (A AND NOT B) OR C. Which gate do you draw first, and why?

Show what happens

The NOT gate on B, because it takes an input directly. Then the AND gate (A and NOT B), then the OR gate (the AND output and C).

The method: start with the gates nearest the inputs (inside the brackets, and any NOT on a single input), draw each gate’s output wire into the gate that uses it, and label every input on the left and the output on the right. If you cannot draw, describe the circuit gate by gate instead: which inputs or gate outputs go into each gate, and where its output goes.

Think it through

Sketch the circuit for Q = (A AND NOT B) OR C on paper or the whiteboard, then reveal the drawing to compare.

Show a model answer
Gate 1, NOT, takes B. Gate 2, AND, takes A and the output of gate 1. Gate 3, OR, takes the output of gate 2 and C. The output of gate 3 is Q. Q = (A AND NOT B) OR C
The sprinkler circuit: Q = (A AND NOT B) OR C

Check yours: NOT on B only; A and NOT B into AND; the AND output and C into OR.

Check your understanding

How many gates does the circuit for Q = (A OR B) AND NOT C need?
Show the answer

Answer: A. Three: OR, NOT and AND.

One gate for each gate name in the expression.

Stage: Apply

From a description straight to a circuit

The science preparation room’s door is upgraded. It now opens if a staff card is valid (A), and either the PIN is correct (B) or a teacher in the room presses the release button (C).

Think it through

Sketch the circuit for the new door directly from the description. Write its expression underneath.

Show a model answer
Gate 1, OR, takes B and C. Gate 2, AND, takes A and the output of gate 1. The output of gate 2 is Q. Q = A AND (B OR C)
The upgraded door: Q = A AND (B OR C)

B OR C first, then AND with A. A valid card is always needed; then either the PIN or the release.

Draw the circuit exactly as the description states it, one gate for each condition, without looking for a shorter version. The Cambridge IGCSE specification asks for circuits drawn for the statement given, without simplification, with at most three inputs and one output.

Stage: Discover

Working backwards from a truth table

Sometimes you are given only what a circuit must do, as a truth table, and you have to find the expression.

ABCQ
0000
0010
0100
0110
1000
1011
1101
1111

Think it through

Look only at the rows where Q = 1. What is A in every one of them?

Show what happens

A is 1 in all three. So A must be 1 for Q to be 1.

Check your understanding

When A = 1, what else is needed for Q to be 1?
Show the answer

Answer: B. At least one of B and C must be 1.

So Q = A AND (B OR C): the upgraded door’s circuit, found from its table.

Check your understanding

A two-input table has Q = 1 only in the row A = 1, B = 0. Which expression gives it?
Show the answer

Answer: C. Q = A AND NOT B

When only one row gives 1, describe that row with AND, putting NOT on each input that is 0.

Go deeper When no pattern is clear: one term for each row with Q = 1

Describe each row where Q = 1 as the inputs joined by AND, with NOT on each input that is 0 in that row, then join those descriptions with OR. For the table above: (A AND NOT B AND C) OR (A AND B AND NOT C) OR (A AND B AND C). Because each gate has two inputs, a three-input description is written with brackets, such as ((A AND NOT B) AND C). The result is always correct, but longer than an expression found from a pattern, so look for a pattern first.

Stage: Apply

From a truth table to a circuit

A circuit must give this table: Q is 1 only in the rows 001, 011 and 101, and 0 in every other row.

Think it through

Find the pattern, write the expression, then sketch the circuit.

Show a model answer
Gate 1, AND, takes A and B. Gate 2, NOT, takes the output of gate 1. Gate 3, AND, takes the output of gate 2 and C. The output of gate 3 is Q. Q = NOT (A AND B) AND C
One circuit that gives the table: Q = NOT (A AND B) AND C

C is 1 in every row with Q = 1; the only row with C = 1 and Q = 0 is 111, where A and B are both 1. So Q = NOT (A AND B) AND C.

Check a design by completing its truth table, with a working column for each gate before the last, and comparing it with the one you were given.

Complete the table for Q = NOT (A AND B) AND C and compare it with the rows above
Gate 1, AND, takes A and B. Gate 2, NOT, takes the output of gate 1. Gate 3, AND, takes the output of gate 2 and C. The output of gate 3 is Q. Q = NOT (A AND B) AND C
Q = NOT (A AND B) AND C
ABCA AND B (working)NOT (A AND B) (working)Q
000
001
010
011
100
101
110
111

    Show the completed table
    ABCA AND BNOT (A AND B)Q
    000010
    001011
    010010
    011011
    100010
    101011
    110100
    111100

    Stage: Check

    Find the mistake

    Kai designed a circuit for the school alarm: it should sound if a door is opened (D) while the alarm is set (S), or if the panic button (P) is pressed. Kai’s circuit is below.

    Gate 1, OR, takes S and P. Gate 2, AND, takes D and the output of gate 1. The output of gate 2 is Q. Q = D AND (S OR P)
    Kai’s design: Q = D AND (S OR P)

    Check your understanding

    Which situation shows that Kai’s design is wrong?
    Show the answer

    Answer: A. The panic button is pressed with every door shut.

    A single row where the design and the description disagree proves a design wrong. The correct circuit is (D AND S) OR P.

    Stage: Consolidate

    Design challenge

    A school minibus has a safety system that decides whether the engine may start. The situation is fictional.

    Think it through

    A minibus starts (Q) if the key is in (A) and the seat belt is fastened (B), but not if the fuel cap is open (C). Write the expression, sketch the circuit, and check one row of your choice.

    Show a model answer
    Gate 1, AND, takes A and B. Gate 2, NOT, takes C. Gate 3, AND, takes the output of gate 1 and the output of gate 2. The output of gate 3 is Q. Q = (A AND B) AND NOT C
    One correct design: Q = (A AND B) AND NOT C

    Q = (A AND B) AND NOT C. For example, the row A = 1, B = 1, C = 1: A AND B is 1, NOT C is 0, so Q is 0, and the bus does not start with the fuel cap open.

    Check the design: complete every column
    ABCA AND B (working)NOT C (working)Q
    000
    001
    010
    011
    100
    101
    110
    111

      Show the completed table
      ABCA AND BNOT CQ
      000010
      001000
      010010
      011000
      100010
      101000
      110111
      111100

      Think it through

      Which of today’s conversions do you find hardest: description to expression, expression to circuit, or table to expression? What would help?

      Show a model answer

      There is no wrong answer. If it is table to expression, look at the rows with Q = 1 and ask what they share; if nothing, use one term per row. If it is drawing, write the expression first and draw the innermost gate first.

      • From a description: find the inputs, then the joining words (and, or, not, unless, while), then write the expression.
      • From an expression to a circuit: draw the innermost gates first and feed each output on.
      • From a table: look at the rows with Q = 1 and find what they share; if nothing is clear, write one term per row.
      • Test every design by completing its truth table and comparing it with the description or table.

      Sources and scope

      • What this lesson is. The fourth of four draft lessons on Boolean logic, written for this site, awaiting the site owner’s editorial review. Its curriculum links are provisional: the wording of each linked specification point has been checked against the published specification, but no link has yet been verified by the site owner. The links show where the lesson may help with a course; they do not imply that any examination board has reviewed or endorsed it.
      • Original material. The sprinkler, the corridor light, the laptop, the upgraded door, Kai’s design and the minibus are fictional examples written for this lesson.
      • Method from a truth table. Finding a pattern, and one term for each row with an output of 1, are standard methods; the lesson uses tables whose patterns can be found, as introductory examples do.