Logical Operators and Truth Tables
What Are Logical Operators?
Computers make decisions by evaluating conditions that are either true or false. Logical operators are the building blocks of this decision-making. They combine Boolean values — values that are either 1 (true) or 0 (false) — and produce a Boolean result. In hardware, these operators are implemented as logic gates. In software, they appear inside if statements and while loops. Understanding them is essential for both circuit design and programming.
A truth table is the standard way to describe a logical operator’s behaviour. Each row represents one combination of inputs. For two inputs A and B there are four possible combinations: (0,0), (0,1), (1,0) and (1,1). You must always show every row — leaving rows out drops marks in the exam.
There are four logical operators you need to know: AND, OR, NOT and XOR. Each has a standard symbol used in circuit diagrams and a truth table showing every possible input-output combination.
The AND Operator
AND outputs 1 only when both inputs are 1. Think of it as a strict gatekeeper: every condition must be met. In Boolean notation, AND is written with a dot or by placing letters side by side: A·B or AB.
| A | B | A AND B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
The OR Operator
OR outputs 1 when at least one input is 1. It only outputs 0 when both inputs are 0. In Boolean notation, OR is written with a plus sign: A + B.
| A | B | A OR B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
The NOT Operator
NOT is a single-input operator that inverts its input: 0 becomes 1 and 1 becomes 0. It is also called a complement or inverter. In Boolean notation, NOT is written as an overbar — for example, NOT A is written as Ā (A with an overbar) — or sometimes as A′ or !A.
| A | NOT A |
|---|---|
| 0 | 1 |
| 1 | 0 |
The XOR Operator
XOR (exclusive OR) outputs 1 when the inputs are different. If both inputs are the same — both 0 or both 1 — the output is 0. XOR is denoted A ⊕ B. It is particularly useful in binary addition circuits (half adders) and encryption.
| A | B | A XOR B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
XOR outputs 1 only when its two inputs differ. This distinguishes it from OR: OR outputs 1 when both inputs are 1, but XOR outputs 0 in that case because the inputs are the same.
Real circuits chain several gates together. Consider the expression NOT A AND B. To build the truth table, add an intermediate column for NOT A before the final output column.
| A | B | NOT A | NOT A AND B |
|---|---|---|---|
| 0 | 0 | 1 | 0 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 0 |
| 1 | 1 | 0 | 0 |
Notice the extra intermediate column. In the exam, when a question includes a combined circuit, fill in every intermediate column. Do not skip straight to the output column.
The most common error in truth table questions is confusing XOR with OR. Remember: OR outputs 1 for the row (1,1), but XOR outputs 0 for that row because the inputs are the same. Write the row (1,1) carefully for every XOR column.
A second mistake is filling in only the output column for combined-gate questions. Intermediate columns are part of the answer, not rough working. If the question shows a two-stage gate circuit, add an intermediate column for each gate stage and fill every row before moving to the final output.
A third mistake is mixing up Boolean notation with arithmetic. In Boolean expressions, A·B means AND and A + B means OR. The + symbol does NOT mean addition here. Students who confuse arithmetic addition with Boolean OR often get three-variable expressions wrong.
NAND and NOR Gates
The course names four logical operators: AND, OR, NOT and XOR. Two further gates build on them and are worth knowing: NAND and NOR. A NAND gate is AND followed by NOT — its output is the inverse of AND. A NOR gate is OR followed by NOT — its output is the inverse of OR. NAND and NOR are called universal gates because any logic circuit can be built from NAND gates alone (or NOR gates alone).
| A | B | NAND | NOR |
|---|---|---|---|
| 0 | 0 | 1 | 1 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 |
Notice that NAND outputs 0 only in the last row (both inputs 1), while NOR outputs 1 only in the first row (both inputs 0). These are exactly opposite to AND and OR respectively. The practical importance of universal gates is that hardware manufacturers can produce one type of gate in bulk and use it to build every other gate, simplifying chip design and reducing manufacturing costs.