impera Open Impera

A levels Computer Science · Computer systems

Boolean algebra and logic gates

1Logic gates and truth tables

A logic gate takes one or more binary inputs and gives a binary output.

ABNOT AA AND BA OR BA XOR BA NAND BA NOR B
00100011
01101110
10001110
11011000

Notation: NOT A is written ¬A or Ā; A AND B as A·B or A ∧ B; A OR B as A + B or A ∨ B; XOR as A ⊕ B.

NAND and NOR are universal gates: any circuit can be built from NAND gates alone.

Check yourself

What is the output of NAND when both inputs are 1?

  • 2

  • It depends on the gate

  • 0

  • 1

Show the answer

0

NOT (1 AND 1).

2Circuits and Boolean expressions

A logic circuit combines gates. Each circuit can be written as a Boolean expression.

Worked example

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

  1. Work out the inner parts first, column by column.
  2. For A = 1, B = 0, C = 0: A·B = 0, ¬C = 1, so Q = 0 + 1 = 1.
  3. A full truth table for 3 inputs needs 2³ = 8 rows.
ABCA·B¬CQ
000011
001000
111101

(Only three of the eight rows are shown.)

Check yourself

How many rows does the truth table for 4 inputs need?

  • 4

  • 8

  • 16

  • 32

Show the answer

16

2⁴.

3Boolean laws

LawAND formOR form
identityA·1 = AA + 0 = A
nullA·0 = 0A + 1 = 1
idempotentA·A = AA + A = A
complementA·¬A = 0A + ¬A = 1
double negation¬¬A = A
absorptionA·(A + B) = AA + A·B = A
distributiveA·(B + C) = A·B + A·CA + B·C = (A + B)·(A + C)
De Morgan¬(A·B) = ¬A + ¬B¬(A + B) = ¬A·¬B

De Morgan's laws: "break the bar and change the sign".

Check yourself

What is ¬(A + B) by De Morgan's law?

  • ¬A + ¬B

  • A · B

  • ¬A · ¬B

  • ¬A + B

Show the answer

¬A · ¬B

Break the bar, change OR to AND.

4Simplifying expressions

Worked example

Simplify A·B + A·¬B

  1. Take out the common factor A: A·(B + ¬B).
  2. B + ¬B = 1 (complement law).
  3. A·1 = A (identity law).
Worked example

Simplify ¬(¬A + B)

  1. De Morgan: ¬¬A · ¬B.
  2. Double negation: A·¬B.
Worked example

Simplify (A + B)·(A + ¬B)

  1. Expand: A·A + A·¬B + B·A + B·¬B.
  2. A·A = A and B·¬B = 0: A + A·¬B + A·B.
  3. Absorption: A + (anything AND A) = A.

Simpler expressions need fewer gates, so circuits are cheaper, smaller and faster.

Check yourself

What does A + A·B simplify to?

  • B

  • A·B

  • A

  • 1

Show the answer

A

Absorption.

5Adders

A half adder adds two bits, giving a sum and a carry.

A half adder. The XOR gate gives the sum bit and the AND gate gives the carry bit.

ABSum (A ⊕ B)Carry (A·B)
0000
0110
1010
1101

A full adder also adds a carry in from the previous column:

  • Sum = A ⊕ B ⊕ C_in
  • C_out = A·B + C_in·(A ⊕ B)

Chaining full adders, each carry out feeding the next carry in, adds whole binary numbers.

Check yourself

What are the outputs of a half adder for A = 1, B = 1?

  • Sum 1, carry 0

  • Sum 0, carry 0

  • Sum 0, carry 1

  • Sum 1, carry 1

Show the answer

Sum 0, carry 1

1 + 1 = 10 in binary.

6Flip-flops and Karnaugh maps

A D-type flip-flop stores one bit. On each rising edge of the clock signal, its output Q takes the value of the data input D, then holds it until the next clock edge. Flip-flops are used to build registers and memory.

A Karnaugh map is a grid used to simplify expressions. Cells with 1 are grouped in rectangles of 1, 2, 4 or 8; each group gives one simple term.

Worked example

A 2-variable map for ¬A·B + A·¬B + A·B

  1. Put 1s in the cells for (A, B) = (0, 1), (1, 0) and (1, 1).
  2. The two 1s with A = 1 form a group: A.
  3. The two 1s with B = 1 form a group: B.
  4. Result: A + B.
B = 0B = 1
A = 001
A = 111
Check yourself

What does a D-type flip-flop store?

  • An analogue voltage value

  • A whole byte of data at once

  • A program and its instructions

  • One bit, updated on the clock edge

Show the answer

One bit, updated on the clock edge

Basis of registers.

Now test yourself

This lesson has a 8-question quiz and 5 exam-style questions with mark schemes in Impera. Free, with your progress saved.

Practise in Impera