Note AcademyNote Academy

Computer Science 2210 · Chapter 10

Boolean Logic

The six logic gates and their truth tables, and how to write an expression for a circuit, complete a truth table, draw a circuit from an expression, and build a circuit from a problem statement.

Written for the 2023–2025 syllabus · 9 min read

Logic gates

NOT

The NOT logic gate is the only logic gate with one input; the rest have two.

The NOT gate symbol

The NOT gate symbol
Input AOutput X
01
10

The truth table, which is used to trace the output of logic gates, shows that with input A, it gives output X.

AND

The AND gate symbol

The AND gate symbol
ABX
000
010
100
111

OR

The OR gate symbol

The OR gate symbol
ABX
000
011
101
111

NAND (NOT AND)

The NAND gate symbol

The NAND gate symbol
ABX
001
011
101
110

NOR (NOT OR)

The NOR gate symbol

The NOR gate symbol
ABX
001
010
100
110

XOR

The XOR gate symbol

The XOR gate symbol
ABX
000
011
101
110

Logic expressions, logic circuits, problem statements and truth tables

Writing a logic expression for a logic circuit

A logic circuit: A goes through a NOT gate (1) into an AND gate (3) with B, C goes through a NOT gate (2), and gates 3 and 2 feed an OR gate (4) that outputs X

A logic circuit: A goes through a NOT gate (1) into an AND gate (3) with B, C goes through a NOT gate (2), and gates 3 and 2 feed an OR gate (4) that outputs X
  • Logic gate 1: NOT A
  • Logic gate 2: NOT C

To write down the expressions for the other gates, we will have to combine the expressions of the previous gates.

  • Logic gate 3 (logic gate 1 and B): NOT A AND B
  • Logic gate 4 (logic gates 3 and 2): (NOT A AND B) OR NOT C

X = (NOT A AND B) OR NOT C

Completing a truth table from a logic circuit

ABC1 (NOT A)2 (NOT C)3 (1 AND B)X
0001101
0011000
0101111
0111011
1000101
1010000
1100101
1110000

This is how you solve a truth table:

  1. Count the number of gates and make the required number of columns in the working space (columns 1, 2 and 3).
  2. Write the output of each gate one by one. This is where your knowledge of the output of different gates will be useful.
  3. The final output will be written in the column labelled X.

Drawing a logic circuit from a logic expression

The circuit: A and B go into a NAND gate; B and C go into an XOR gate followed by a NOT gate; the NAND and the NOT outputs go into an OR gate that outputs Z

The circuit: A and B go into a NAND gate; B and C go into an XOR gate followed by a NOT gate; the NAND and the NOT outputs go into an OR gate that outputs Z

This is how you make a logic circuit from a logic expression:

  1. Solve the brackets first.
  2. Remember that the NOT gate only has one input and the others have two.
  3. Be careful about the positions of the brackets in the expression.
  4. The dots represent joints. They mean that the same value is to be used somewhere else (here B goes to both the NAND and the XOR).

Writing a logic expression from a truth table

ABCX
0001
0010
0100
0110
1000
1011
1100
1111

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

Tips to solve this type of question:

  • a. The final expression will only consist of the parts where X (the final output) is 1.
  • b. Every time X is 1, A, B and C will be connected using AND.
  • c. Each output where X is 1 will be connected using OR.
  • d. When an input is 1, it will be written as A. When it is 0, it will be written as NOT A.

Building a circuit from a problem statement

Sensor or switchOutput of 1Output of 0
Switch (S1)OnOff
Pressure sensor (P1)≥ 3< 3
Pressure sensor (P2)≥ 3< 3

Create a logic circuit that will produce an output (X) of 1 when:

  • the switch S1 is on, and
  • either P1 is less than 3 or P2 is less than 3, but not both.

All logic gates used must have a maximum of two inputs.

The circuit: P1 and P2 go into an XOR gate, and its output goes into an AND gate with S1, which outputs X

The circuit: P1 and P2 go into an XOR gate, and its output goes into an AND gate with S1, which outputs X

How to solve:

  • a. The word in the middle always represents the last logic gate. In this case, "and" represents the AND gate.
  • b. Secondly, the question states that we need to have an output of 1. Since we already know that the AND gate only gives an output of 1 when both the inputs are 1, we need to make sure both the inputs are 1.
  • c. When the switch S1 is ON, it gives an output of 1, hence we connect it directly to the AND gate.
  • d. The question states that either P1 or P2 needs to be less than 3 but not both. By recalling what we have learnt before, we recognise that this is the output achieved by the XOR gate.
Test yourself17 flashcards on this chapter.Flashcards →

Practise this chapter

Every past-paper question on these topics, with the mark scheme.