Circuits and problem statements

IGCSE Computer Science · Boolean Logic

From expression to circuit

A logic circuit is a diagram of gates wired together. Reading one is a matter of working from the inputs on the left towards the output on the right, labelling the output of each gate as you go.

Building one from an expression works the other way: identify the bracketed parts first, since those are the gates nearest the inputs, and the operation outside the brackets is the gate nearest the output.

For $X = (A \ \text{AND} \ B) \ \text{OR} \ (\text{NOT} \ C)$:

From a problem statement to logic

Exam questions usually describe a real system in words. The method is fixed:

  1. find the inputs, and decide what $1$ means for each — always state this;
  2. find the condition under which the output is $1$;
  3. translate the joining words into gates.

The joining words map directly:

"and", "both", "all of"AND
"or", "either", "at least one"OR
"not", "is off", "is closed", "fails to"NOT
"either … but not both", "differ"XOR

A worked statement

An alarm sounds when the door sensor is open AND the system is armed, or when the panic button is pressed.

Inputs: $D = 1$ means the door is open; $S = 1$ means the system is armed; $P = 1$ means the panic button is pressed.

$$X = (D \ \text{AND} \ S) \ \text{OR} \ P$$

Note the panic button is joined by OR and stands alone — it works whether or not the system is armed. That is exactly what a panic button should do, and getting it wrong (by putting it inside the AND) would make the alarm useless.

Watch the wording carefully

Two phrases that change the answer:

And the one that separates grades: "either A or B but not both" is XOR, not OR. If a question takes the trouble to say "but not both", it is telling you which gate to use.

Checking your answer

Always test the expression against one or two rows you can reason about in words. For the alarm above: if the panic button is pressed but nothing else, then $P = 1$, so $X = 1$. The alarm sounds — which is right.

This check costs seconds and catches most errors.

X = (A AND B) OR (NOT C) Inside brackets → the gate near the INPUT. Outside brackets → the gate near the OUTPUT. A B VÀ A VÀ B C NOT NOT C OR X Reading the circuit: go from LEFT to RIGHT, labelling the output of EACH gate as you pass.
The two gates in brackets run in parallel and only meet at the final gate — that is why the expression has two pairs of brackets.

Worked example: translating a word problem into a logic expression

An alarm bell sounds when the door sensor is open and the system is on, or when the emergency button is pressed. State the inputs, write the logic expression, check the answer, and explain the consequence of putting the emergency button inside the AND gate.

Solution

Step 1 — state the inputs and what a value of $1$ means.

This step must be written down, because without stating it the expression has no defined meaning.

Step 2 — translate the connecting words.

The question says “door open and system on” → an AND gate joins $D$ and $S$.

The question says “or when the emergency button is pressed” → an OR gate joins the result above with $P$.

Step 3 — write the expression.

$$X = (D \ \text{AND} \ S) \ \text{OR} \ P$$

The brackets matter: they show that the AND gate runs first, and only its output goes into the OR gate.

Step 4 — check with a case that can be reasoned through in words.

Try: only the emergency button is pressed, the door is closed, the system is not on.

Then $D = 0$, $S = 0$, $P = 1$.

$D \ \text{AND} \ S = 0$. But an OR gate needs only one value of $1$, and $P = 1$, so $X = 1$.

The bell sounds — as expected.

Try another: the door is open but the system is not on, and nobody presses the button. $D = 1$, $S = 0$, $P = 0$. Then $D \ \text{AND} \ S = 0$ and $P = 0$, so $X = 0$. The bell does not sound — also correct, because when the system is not on, opening the door is normal.

The consequence of putting the emergency button inside the AND gate.

The wrong expressions would be $X = D \ \text{AND} \ S \ \text{AND} \ P$, or $X = (D \ \text{OR} \ P) \ \text{AND} \ S$.

In both wrong forms, the bell only sounds when the system is on.

Why that is a serious error. The emergency button exists precisely to be used in an unexpected situation — when someone breaks in during the day, when the alarm system is off.

An emergency button that only works when the system is on is useless, because at the moment it is needed most, it does not sound.

This is an example of why you must read the sentence structure carefully: the word “or” in the question puts the emergency button on its own, outside the pair of brackets.

Worked example: when to use XOR

A furnace warning system must switch on when one of the two temperature sensors reports overheating, but not both — because both reporting together means the furnace is really on fire and needs a different procedure. Write the expression, build the truth table, and explain why using an OR gate here is wrong.

Solution

Identifying the gate.

The deciding phrase is “but not both”. When a question takes the trouble to add this phrase, it is pointing out the gate to use: the XOR gate.

Inputs. $A = 1$ means the first sensor reports overheating; $B = 1$ means the second sensor reports overheating.

Expression.

$$X = A \ \text{XOR} \ B$$

Truth table. There are two inputs so there are $2^2 = 4$ rows.

$A = 0$, $B = 0$ → $X = 0$ (no sensor reports, no warning)

$A = 0$, $B = 1$ → $X = 1$ (one sensor reports, warning on)

$A = 1$, $B = 0$ → $X = 1$ (one sensor reports, warning on)

$A = 1$, $B = 1$ → $X = 0$ (both report together, this warning is not switched on)

Why using an OR gate is wrong.

An OR gate gives $X = 1$ when at least one input equals $1$, including when both equal $1$.

The first three rows of the two tables are identical. They differ in exactly the last row: the OR gate gives $1$ there, while the XOR gate gives $0$.

The real-world consequence of using the wrong one. When both sensors report together — meaning the furnace is really on fire — a system using an OR gate would trigger the same warning as when only one sensor reports.

Staff see the familiar signal and respond with the normal procedure, when the real situation demands a completely different emergency procedure.

In other words, an error in one row of the truth table makes the system unable to tell apart two situations of completely different levels of danger.

A way to remember so as not to mix them up again: the OR gate is “tea or coffee, taking both is fine too”; the XOR gate is “tea or coffee, but not both”.

Common mistake

Ignoring the phrase “but not both” in a question and using an OR gate instead of XOR. When a question takes the trouble to add that phrase, it is pointing straight at the gate to use — question writers do not add unnecessary words. The two gates are identical in the first three rows so the work still looks reasonable, and goes wrong only in the last row — but that is often the row most important in practice: two sensors reporting together means a much more dangerous situation than one sensor reporting. The second trap, of the same “careless reading” kind: putting an input that stands on its own inside the brackets. In the sentence “the bell sounds when the door is open and the system is on, or when the emergency button is pressed”, the emergency button is joined by an OR gate and sits outside the brackets — it must work regardless of whether the system is on. Mistakenly putting it inside the AND gate makes the emergency button sound only when the system is already on, that is, useless at exactly the moment it is needed most.

Key takeaway

Building a circuit from an expression: what is inside the brackets is the gate near the input, the operation outside the brackets is the gate near the output. To read a circuit, go left to right and label the output of each gate. For word problems: state clearly what $1$ means for each input, find the condition for the output to equal $1$, then translate the connecting words — “and” → AND, “or” → OR, “not / off” → NOT, “but not both” → XOR. Finally always try one row that can be reasoned through in words — this check takes a few seconds and catches most errors.

← The six logic gates · All IGCSE Computer Science lessons · Practice IGCSE Computer Science questions (free, instant scoring)