Study Guide

Logic Expressions and Truth Tables

Working out exactly what a logic circuit does: listing every combination of three inputs, reading and writing logic expressions, and completing truth tables with working columns from a circuit, an expression or a description.

Lesson 2.3 Boolean Logic

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

Stage: Think

How many situations?

A school greenhouse has a fan. Its controller checks three things: is it too hot (A), is the roof window shut (B), and has the gardener pressed the override button (C)? Each is 1 or 0.

Think it through

How many different situations can the controller be in? How do you know you have them all?

Show what happens

Eight. Each of the four situations for A and B can happen with C = 0 or with C = 1, so adding an input doubles the number: 2 × 2 × 2 = 8.

To list all eight without missing one, count in binary: 000, 001, 010, 011, 100, 101, 110, 111. C changes every row, B every two rows and A every four.

Check your understanding

In a three-input truth table, which row comes straight after A = 0, B = 1, C = 1?
Show the answer

Answer: B. A = 1, B = 0, C = 0

After 011 comes 100, just as 3 is followed by 4.

Stage: Discover

Writing a circuit down

Here is the greenhouse fan’s circuit.

Gate 1, AND, takes A and B. Gate 2, OR, takes the output of gate 1 and C. The output of gate 2 is Q.
The greenhouse fan

Think it through

Describe in words what this circuit does, starting from the inputs on the left.

Show what happens

A and B go into an AND gate. Its output and C go into an OR gate, which gives Q. So the fan runs when it is too hot and the window is shut, or when the override is pressed.

The same description can be written as a logic expression: Q = (A AND B) OR C. The brackets go round the gate that must be worked out first, the one nearest the inputs. A logic circuit and its expression describe exactly the same thing.

Gate 1, AND, takes B and C. Gate 2, OR, takes A and the output of gate 1. The output of gate 2 is Q.
Another circuit

Check your understanding

Which logic expression matches this circuit?
Show the answer

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

Brackets go round the first gate: here B AND C.

Stage: Experiment

Completing a circuit’s truth table

To complete a truth table for a circuit, work it out in the same order as the circuit: first each gate nearest the inputs, then the gates they feed. Each early gate gets its own working column.

  1. Working column first. The AND gate gets A = 1 and B = 1. AND gives 1 only when both inputs are 1, so A AND B is 1. Write 1 in the working column.
  2. Then the last gate. The OR gate gets the working column’s 1 and C = 0. OR gives 1 when at least one input is 1, so Q = 1.

It is too hot and the window is shut, so the fan runs even though nobody pressed the override. Change one fact, B to 0 (the window is open): A AND B becomes 0, and with C = 0 as well, Q becomes 0.

The greenhouse fan: the working column is done; complete Q
Gate 1, AND, takes A and B. Gate 2, OR, takes the output of gate 1 and C. The output of gate 2 is Q. Q = (A AND B) OR C
Q = (A AND B) OR C
ABCA AND B (working)Q
0000
0010
0100
0110
1000
1010
1101
1111

    Show the completed table
    ABCA AND BQ
    00000
    00101
    01000
    01101
    10000
    10101
    11011
    11111

    Now a circuit with both columns blank. Do the working column first, all the way down, then Q.

    Complete both columns for Q = (A OR B) AND C
    Gate 1, OR, takes A and B. Gate 2, AND, takes the output of gate 1 and C. The output of gate 2 is Q. Q = (A OR B) AND C
    Q = (A OR B) AND C
    ABCA OR B (working)Q
    000
    001
    010
    011
    100
    101
    110
    111

      Show the completed table
      ABCA OR BQ
      00000
      00100
      01010
      01111
      10010
      10111
      11010
      11111

      Think it through

      In the second table, explain why Q is 0 in the row A = 1, B = 1, C = 0, even though both A and B are 1.

      Show a model answer

      A OR B is 1, but the AND gate also needs C, and C is 0. AND gives 1 only when both its inputs are 1, so Q is 0.

      Stage: Check

      The order matters

      Check your understanding

      Lee works out Q = A OR (B AND C) for A = 1, B = 0, C = 0 like this: “A OR B is 1, then 1 AND C is 0, so Q = 0.” What has gone wrong?
      Show the answer

      Answer: A. Lee worked the gates in the wrong order: B AND C comes first, so Q = 1.

      Brackets decide the order, just as in arithmetic. Working left to right and ignoring them is a common mistake in truth tables.

      A working column is not optional decoration. Skipping it means holding the middle of the circuit in your head, and that is where most errors start. Work out the inner gate for every row first, then the next.

      Stage: Experiment

      From an expression to a truth table

      Sometimes you are given only the expression: Q = (A OR B) AND NOT C.

      Think it through

      Which working columns will you need before you can work out Q?

      Show what happens

      Two: A OR B, and NOT C. Q is then the AND of those two columns.

      Complete the table for Q = (A OR B) AND NOT C
      ABCA OR B (working)NOT C (working)Q
      000
      001
      010
      011
      100
      101
      110
      111

        Show the completed table
        ABCA OR BNOT CQ
        000010
        001000
        010111
        011100
        100111
        101100
        110111
        111100

        Stage: Apply

        From a description to a truth table

        A school alarm sounds (Q) if a door is opened (D) while the alarm is set (S), or if the panic button (P) is pressed.

        Think it through

        Which conditions must be true together, and which one works on its own?

        Show what happens

        The door being opened and the alarm being set must both be true (“while” means at the same time). The panic button works on its own.

        Complete Q for every row from the description alone. The rows follow the inputs in alphabetical order: D, P, S.

        The school alarm
        DPSQ (alarm)
        000
        001
        010
        011
        100
        101
        110
        111

          Show the completed table
          DPSQ (alarm)
          0000
          0010
          0101
          0111
          1000
          1011
          1101
          1111

          Stage: Apply

          A circuit to write and work out

          Gate 1, a gate with a curved back, a second curved line just behind it, and a pointed front, takes A and B. Gate 2, a gate with a flat back and a rounded front, takes the output of gate 1 and C. The output of gate 2 is Q.
          A circuit with unlabelled gates
          Go deeper The two gates described in words
          • Gate 1 takes inputs A and B: a curved back with a second curve just behind it, and a pointed front, with nothing on the output.
          • Gate 2 takes the output of Gate 1 and input C: a flat back and a round front, with nothing on the output. Its output is Q.

          Apply it

          Identify the gates from their symbols. Which expression describes this circuit?
          Show the answer

          Answer: B. Q = (A XOR B) AND C

          XOR first, then AND with C.

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

            Show the completed table
            ABCA XOR BQ
            00000
            00100
            01010
            01111
            10010
            10111
            11000
            11100

            Stage: Consolidate

            Show what you know

            Think it through

            Write the method you would use to complete the truth table for any circuit with three inputs, as numbered steps someone else could follow.

            Show a model answer
            1. Write the eight input rows in binary counting order, 000 to 111. 2. Add a working column for each gate except the last, starting with the gates nearest the inputs. 3. Fill each working column all the way down. 4. Work out Q from the working columns and inputs it uses. 5. Check one row by tracing it through the circuit.
            Final task: complete the table for Q = A OR NOT (B AND C)
            ABCB AND C (working)NOT (B AND C) (working)Q
            000
            001
            010
            011
            100
            101
            110
            111

              Show the completed table
              ABCB AND CNOT (B AND C)Q
              000011
              001011
              010011
              011100
              100011
              101011
              110011
              111101

              Think it through

              Which kind of table is hardest for you: from a circuit, from an expression, or from a description? Why?

              Show a model answer

              There is no wrong answer. If it is descriptions, that is because you have to decide the gates yourself, and the next lesson starts exactly there.

              • Three inputs give eight rows, in binary counting order from 000 to 111.
              • A logic expression writes a circuit in words; brackets go round the gate worked out first.
              • Use a working column for every gate before the last, and fill each one all the way down.
              • The same method works from a circuit, an expression or a description.

              Sources and scope

              • What this lesson is. The third 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 greenhouse fan, the school alarm and Lee’s working are fictional examples written for this lesson.
              • Notation. Expressions use the gate names in capitals with brackets, as the syllabus writes them; a single input after NOT is not bracketed (NOT C).