Computer Science (2210)
Topic 9 of 11Cambridge O Levels

Boolean Logic and Logic Gates

Explore the binary decision-making at the heart of all digital computers using logic gates.

At the core of every digital computer, smartphone, and electronic device are circuits that make simple decisions based on the principles of Boolean logic. Developed by George Boole in the 19th century, this system of algebra deals with two values: TRUE (represented by the binary digit 1) and FALSE (represented by 0). Every complex operation a computer performs is broken down into millions of these simple true/false decisions.


These decisions are physically implemented by logic gates, which are the fundamental building blocks of digital circuits. A logic gate is an electronic circuit that takes one or more binary inputs and produces a single binary output. The Cambridge O Level syllabus requires you to understand several key logic gates.


### Primary Logic Gates


  • AND Gate: The output of an AND gate is 1 only if all of its inputs are 1. Think of it as a logical multiplication. The Boolean expression is written as Q = A . B (or simply AB).

  • OR Gate: The output of an OR gate is 1 if at least one of its inputs is 1. This is like logical addition. The Boolean expression is Q = A + B.

  • NOT Gate (Inverter): This is the simplest gate. It has only one input and one output. The output is the inverse of the input. If the input is 1, the output is 0, and vice versa. The Boolean expression is Q = Ā (read as 'NOT A' or 'A bar').

  • ### Combination Logic Gates


    These gates are derived from the primary gates.


  • NAND Gate (NOT-AND): A NAND gate is an AND gate followed by a NOT gate. Its output is 0 only when all its inputs are 1 (the exact opposite of an AND gate). It is a universal gate, meaning any other logic gate can be constructed using only NAND gates. The Boolean expression is Q = A.B.

  • NOR Gate (NOT-OR): A NOR gate is an OR gate followed by a NOT gate. Its output is 1 only when all its inputs are 0 (the opposite of an OR gate). Like the NAND gate, the NOR gate is also a universal gate. The Boolean expression is Q = A+B.

  • XOR Gate (Exclusive-OR): The output of an XOR gate is 1 only if its inputs are different. For example, if A=1 and B=0, the output is 1. But if A=1 and B=1, the output is 0. This is useful for tasks like binary addition and error checking. The Boolean expression is Q = A ⊕ B.

  • ### Truth Tables


    A truth table is a crucial tool used to represent the output of a logic gate or a more complex logic circuit for all possible combinations of its inputs. For a circuit with 'n' inputs, the truth table will have 2ⁿ rows. For a 2-input gate (like AND, OR, XOR), there are 2² = 4 possible input combinations (00, 01, 10, 11).


    Example Truth Table for a 2-Input AND gate:

    | A | B | Q (A.B) |

    |---|---|---------|

    | 0 | 0 | 0 |

    | 0 | 1 | 0 |

    | 1 | 0 | 0 |

    | 1 | 1 | 1 |


    ### Designing Simple Logic Circuits


    Individual logic gates can be combined to create logic circuits to perform more complex tasks. To analyse or design a circuit, you follow a clear process:


  • Write the Boolean Expression: Define the logical relationship between inputs and the final output.
  • Draw the Logic Circuit Diagram: Represent the expression using the standard symbols for each logic gate, connecting them in the correct order.
  • Create a Truth Table: Systematically work out the output for every possible combination of inputs. This often involves creating intermediate columns in the table to track the output of each gate in the circuit.

  • Example Circuit: Consider the expression **Q = (A . B) + C**.

  • Circuit: An AND gate takes inputs A and B. Its output is then fed into one input of an OR gate. The other input of the OR gate is C. The final output is Q.
  • Truth Table: Since there are 3 inputs (A, B, C), there are 2³ = 8 possible input combinations. We would create a table with columns for A, B, C, an intermediate column for (A.B), and the final column for Q.
  • Key Points to Remember

    • 1Boolean logic is a system of reasoning using two values: TRUE (1) and FALSE (0).
    • 2Logic gates are electronic circuits that perform Boolean operations on binary inputs.
    • 3The three fundamental gates are AND (output is 1 if all inputs are 1), OR (output is 1 if any input is 1), and NOT (inverts the input).
    • 4NAND and NOR gates are known as 'universal gates' because any other logical function can be built from them.
    • 5The XOR (Exclusive-OR) gate produces a 1 output only when its inputs are different.
    • 6A truth table systematically lists all possible input combinations for a logic circuit and shows the corresponding output for each.
    • 7Logic circuits are created by connecting the outputs of some logic gates to the inputs of others to perform complex tasks.
    • 8Boolean expressions use operators like . (AND), + (OR), and a bar (NOT) to represent the function of a logic circuit algebraically.

    Pakistan Example

    Logic Gates in a UPS/Generator Automatic Transfer Switch (ATS)

    In many homes and businesses in Pakistan, an Automatic Transfer Switch (ATS) is used to switch from the main grid power (WAPDA/K-Electric) to a backup UPS or generator during load-shedding. A simple logic circuit controls this. Let Input **A** be 'Grid Power Available' (1=Yes, 0=No). The system should only activate the generator when grid power is NOT available. This requires a **NOT** gate. The condition to start the generator could be expressed as: 'Start Generator if (**NOT A**)'. This ensures the generator only runs when needed, preventing fuel wastage and damage, a practical application of Boolean logic seen daily across the country.

    Quick Revision Infographic

    Computer Science — Quick Revision

    Boolean Logic and Logic Gates

    Key Concepts

    1Boolean logic is a system of reasoning using two values: TRUE (1) and FALSE (0).
    2Logic gates are electronic circuits that perform Boolean operations on binary inputs.
    3The three fundamental gates are AND (output is 1 if all inputs are 1), OR (output is 1 if any input is 1), and NOT (inverts the input).
    4NAND and NOR gates are known as 'universal gates' because any other logical function can be built from them.
    5The XOR (Exclusive-OR) gate produces a 1 output only when its inputs are different.
    6A truth table systematically lists all possible input combinations for a logic circuit and shows the corresponding output for each.
    Pakistan Example

    Logic Gates in a UPS/Generator Automatic Transfer Switch (ATS)

    In many homes and businesses in Pakistan, an Automatic Transfer Switch (ATS) is used to switch from the main grid power (WAPDA/K-Electric) to a backup UPS or generator during load-shedding. A simple logic circuit controls this. Let Input **A** be 'Grid Power Available' (1=Yes, 0=No). The system should only activate the generator when grid power is NOT available. This requires a **NOT** gate. The condition to start the generator could be expressed as: 'Start Generator if (**NOT A**)'. This ensures the generator only runs when needed, preventing fuel wastage and damage, a practical application of Boolean logic seen daily across the country.

    SeekhoAsaan.com — Free RevisionBoolean Logic and Logic Gates Infographic

    Test Your Knowledge!

    5 questions to test your understanding.

    Start Quiz