Logic gates and truth tables

A-Level Computer Science · Logic Gates and Boolean Algebra

Six gates

NOT inverts. AND outputs 1 only when both inputs are 1. OR outputs 1 when at least one input is 1. NAND and NOR are AND and OR followed by NOT. XOR outputs 1 when the inputs differ — read it as "one or the other but not both".

Notation you must be able to switch between

$\overline{A}$ for NOT $A$; $A\cdot B$ (or $AB$) for AND; $A+B$ for OR; $A\oplus B$ for XOR. Exam questions move freely between logic diagrams, Boolean expressions and truth tables, and a large share of the marks is simply translating between the three without error.

Building a truth table properly

List inputs in binary counting order — $00,01,10,11$ for two inputs, eight rows for three. Then add one column per intermediate signal, not just the final output. Working column by column is what stops mistakes in a circuit with four gates, and examiners award marks for correct intermediate columns.

Reading a circuit

Work left to right, labelling the output of every gate before moving on. If a wire branches, the same signal feeds both destinations — a branch is not a new variable.

NAND and NOR are universal

Any circuit can be built from NAND gates alone (or NOR gates alone), which matters commercially: manufacturing one gate type is cheaper than manufacturing six.

Mach nua cong (half adder)ABXORANDS = A XOR B (tong)C = A AND B (nho)1 + 1 = 0 nho 1 — dung hai cong nay la du
The half adder is the classic example linking logic to arithmetic: XOR gives the sum bit, AND gives the carry bit. Look at the truth tables of these two gates and you immediately see $1+1=0$ carry $1$.

Worked example: building a truth table for a three-input circuit

Given the expression $X = (A \cdot \overline{B}) + (B \cdot C)$.

Build the complete truth table, including the intermediate columns.

Solution

Step 1: list the $8$ rows in binary counting order and add a column for $\overline{B}$, a column for $A\cdot\overline{B}$ and a column for $B\cdot C$ before the $X$ column.

$A\,B\,C \mid \overline{B} \mid A\overline{B} \mid BC \mid X$

$0\,0\,0 \mid 1 \mid 0 \mid 0 \mid 0$
$0\,0\,1 \mid 1 \mid 0 \mid 0 \mid 0$
$0\,1\,0 \mid 0 \mid 0 \mid 0 \mid 0$
$0\,1\,1 \mid 0 \mid 0 \mid 1 \mid 1$
$1\,0\,0 \mid 1 \mid 1 \mid 0 \mid 1$
$1\,0\,1 \mid 1 \mid 1 \mid 0 \mid 1$
$1\,1\,0 \mid 0 \mid 0 \mid 0 \mid 0$
$1\,1\,1 \mid 0 \mid 0 \mid 1 \mid 1$

Step 2: check by reading the expression aloud. $X=1$ when ($A$ is on and $B$ is off) or ($B$ and $C$ are both on). The four rows giving $X=1$ are $011$, $100$, $101$, $111$; checking each row confirms that description.

Why intermediate columns are needed. If you fill in the $X$ column directly, an error in row $110$ (easily mistaken for $1$ because $A=1$) has no way of being caught. With the $A\overline{B}$ column showing clearly that $\overline{B}=0$, so the product is $0$, the mistake shows up at once.

Common mistake

Confusing XOR with OR. OR gives $1$ on the $1\,1$ row; XOR gives $0$. Only one row differs, but it is the deciding row in every adder circuit, and getting it wrong makes the whole adder question wrong.

Key takeaway

Know the truth tables of the six gates, be able to write the same circuit in all three ways (diagram, expression, table), and always add intermediate columns when building a table; that is both the way to avoid errors and where the marks are.

← The Internet: protocols, addressing and packet switching · All A-Level Computer Science lessons · Practice A-Level Computer Science questions (free, instant scoring) · Boolean algebra and simplification →