Home / GCSE · AQA / Computer Science / Computer systems

CS14Logic Gates, Truth Tables and Boolean Expressions

3.4.2 Boolean logic

Logic gates and their symbols

A computer's processor is built from millions of tiny switches. Groups of them form logic gates, which work on binary values: 1 (on, true) and 0 (off, false).

  • Logic gate (AQA): “an electronic component that takes one or more binary inputs and performs a basic logical operation (such as AND, OR and NOT) to produce a single binary output.”
  • You need four gates: NOT, AND, OR and XOR. You don't need NAND or NOR.
  • NOT has one input. It flips it: 1 becomes 0 and 0 becomes 1.
  • AND outputs 1 only when both inputs are 1.
  • OR outputs 1 when at least one input is 1 (so also when both are).
  • XOR (exclusive OR) outputs 1 when exactly one input is 1: the inputs are different.
  • Learn the shapes. AND has a flat back and a round front (a D shape). OR has a curved back and a pointed front. XOR is an OR with an extra curved line behind it. NOT is a triangle with a small circle at its tip.

The four gates in the shapes AQA uses, with the Boolean expression for each.

Exam tipDraw gates with a ruler and make AND and OR clearly different. AQA's examiners gave no marks for gates they couldn't tell apart.
Logic gate
An electronic component that takes one or more binary inputs and performs a basic logical operation (such as AND, OR and NOT) to produce a single binary output.
XOR
Exclusive OR: the output is 1 when exactly one input is 1.
3.4.2 Boolean logic

Truth tables for the four gates

Truth table (AQA): “a representation of the output of a logical expression or circuit for all possible combinations of input variables.”

  • Two inputs give 4 rows: 00, 01, 10, 11.
  • AND and OR differ in two rows (01 and 10). OR and XOR differ only in the last row (11).
  • A quick way to remember: AND is 1 in one row, OR is 0 in one row, XOR is 1 when the inputs differ.
  • AQA accepts T and F instead of 1 and 0, but not a mixture of the two in one table.
ANOT A
01
10
ABA AND BA OR BA XOR B
00000
01011
10011
11110
Exam tipIf a question shows a truth table and asks for the gate, check the 11 row first. Output 1 there means AND or OR; output 0 means XOR (or NOT, if there's only one input).
Truth table
A representation of the output of a logical expression or circuit for all possible combinations of input variables.
3.4.2 Boolean logic

Writing Boolean expressions

A Boolean expression describes a circuit in one line. AQA uses its own symbols, and you must use them when a question asks for a Boolean expression.

  • AQA's example: (A AND B) OR (NOT C) is written (A . B) + C.
  • Use brackets to show which part is worked out first, for example A . (B + C) is not the same as (A . B) + C.
  • A bar over a group negates the whole group: A + B means NOT (A + B). Make sure the bar covers exactly what is negated.
  • In this notation + means OR, not adding. 1 + 1 is 1.
GateAQA symbolExampleRead it as
AND. (a dot)A . BA and B
OR+A + BA or B
XOR⊕A ⊕ BA XOR B
NOTa bar over the topAnot A
Exam tipWriting the words AND, OR, NOT instead of the symbols scored nothing when AQA asked for a Boolean expression. Restating the question in words (“Q is true when…”) doesn't count either.
Boolean expression
A way of writing a logic circuit using inputs and the operators . (AND), + (OR), ⊕ (XOR) and an overbar (NOT).
3.4.2 Boolean logic

Truth tables with three inputs

Questions can have up to three inputs. Each extra input doubles the number of rows: n inputs give 2n rows.

  • List the inputs in binary counting order: 000, 001, 010, 011, 100, 101, 110, 111. That way you can't miss a row or repeat one.
  • A quick pattern: the first column is four 0s then four 1s; the second is 0 0 1 1 0 0 1 1; the third alternates 0 1 0 1 0 1 0 1.
  • For a three-input AND (A . B . C), the output is 1 only in the last row. For a three-input OR, it is 0 only in the first row.
InputsRows
12
24
38
Exam tipMost truth tables in AQA's papers already have the input columns filled in. If you have to write them yourself, use binary order.
3.4.2 Boolean logic

Truth tables for combined circuits

When a circuit has more than one gate, add a working column for the output of each gate before the final output.

  • Step 1: label the output of each gate (D, E…). Step 2: fill in each working column from the inputs. Step 3: fill in the output from the working columns.
  • Work down a whole column at a time, not across a row: it's quicker and you make fewer slips.
  • Check one row at the end by following it through the circuit by hand.
ABCD = A . BE = CQ = D + E
000011
001000
010011
011000
100011
101000
110111
111101

Q = (A . B) + C̄, with the two gate outputs labelled D and E.

Worked exampleIn the circuit above, what is Q when A = 1, B = 0 and C = 1?
  1. D = A . B = 1 . 0 = 0AND needs both inputs to be 1
  2. E = C = NOT 1 = 0NOT flips the input
  3. Q = D + E = 0 + 0 = 0OR needs at least one input to be 1
Q = 0
3.4.2 Boolean logic

From a circuit to a Boolean expression

Start at the inputs and work towards the output, writing an expression for each gate's output as you go.

  • Write each gate's output in brackets, then put it into the next gate's expression.
  • For the circuit in the previous section: the AND gate gives (A . B), the NOT gate gives C, and the OR gate joins them: Q = (A . B) + C.
  • Check the order of the inputs doesn't matter for the gate: A . B is the same as B . A, and A ⊕ B is the same as B ⊕ A.
  • Check your answer by testing one row of the truth table in your expression.
Worked exampleWrite a Boolean expression for the watering-pump circuit in the next section (inputs D, M and O; output P).
  1. The OR gate has inputs M and O, so it gives (M + O)start at the inputs
  2. The AND gate has inputs D and (M + O)follow the wire to the next gate
  3. P = D . (M + O)the brackets show the OR is worked out first
P = D . (M + O)
Exam tipLeave out the brackets and the meaning can change: D . M + O would usually be read as (D . M) + O, which is a different circuit.
3.4.2 Boolean logic

From a Boolean expression to a circuit

Work the other way: find the part of the expression worked out first (inside the brackets, and any bars over single inputs) and draw that gate first.

  • Draw the inputs down the left-hand side and the output on the right.
  • Each operator is one gate: . is an AND gate, + is an OR gate, ⊕ is an XOR gate, and each bar is a NOT gate.
  • Draw a NOT gate straight after an input that has a bar over it.
  • Join the gates with straight lines. A dot where wires meet shows they are connected; wires that only cross have no dot.
  • Up to three inputs are used in AQA's circuits, and each gate (apart from NOT) has two inputs.
Worked exampleDescribe the circuit for Q = A . (B + C).
  1. A NOT gate on input Athe bar is over A only
  2. An OR gate with inputs B and Cthe bracket is worked out first
  3. An AND gate with the NOT output and the OR output as its inputs; its output is Qthe dot joins the two parts
Three gates: NOT, OR, then AND.
Exam tipUse a ruler and a pencil. Label every input and the output with the letters in the question.
3.4.2 Boolean logic

Designing circuits from a description

Many questions describe a real system with sensors or switches. Turn the words into gates, then into an expression or a circuit.

  • First, give each input and output a letter (usually the question does this) and say what 1 means for each, for example D = 1 when the soil is dry.
  • Then find the gates from the wording, and use brackets to keep the parts together.
  • Interpreting results: once the truth table is complete, read off the rows where the output is 1. They tell you exactly when the system switches on.
The words say…Use
“both”, “and”, “as well as”AND
“either”, “or”, “at least one”OR
“exactly one”, “one but not both”, “different”XOR
“not”, “off”, “isn't”, “unless”NOT

A watering pump runs when the soil is dry and either it is morning or the override button is pressed.

Worked exampleA car beeps (B) when the engine is running (E) and the seatbelt is not fastened (S). Write the Boolean expression.
  1. “Not fastened” is SNOT
  2. Running and not fastened joins them with ANDboth must be true
B = E . S
Worked exampleFor the watering pump, P = D . (M + O), list the input rows (D M O) where P = 1.
  1. D must be 1, so only rows 100 to 111 are possibleAND needs D = 1
  2. M + O must be 1, so 100 is outOR is 0 only when both are 0
101, 110 and 111: the pump runs in three of the eight cases.
3.4.2 Boolean logic

Using XOR and AND to add two bits

A circuit can have more than one output. A circuit that adds two bits, A and B, needs two: a sum bit (S) and a carry bit (C).

  • 1 + 1 = 2, which is 10 in binary: sum 0, carry 1. That's why two outputs are needed.
  • The sum column matches XOR: S = A ⊕ B.
  • The carry column matches AND: C = A . B.
  • The same inputs feed both gates: the dots on the wires show where they branch.
ABC (carry)S (sum)A + B in binary
000000
010101
100101
111010

Adding two bits: XOR gives the sum, AND gives the carry.

LinkAdding binary numbers by hand is in the topic on number bases. This circuit does one column of that addition.