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)$:
- an AND gate takes $A$ and $B$;
- a NOT gate takes $C$;
- an OR gate takes those two outputs and produces $X$.
From a problem statement to logic
Exam questions usually describe a real system in words. The method is fixed:
- find the inputs, and decide what $1$ means for each — always state this;
- find the condition under which the output is $1$;
- 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:
- "only if both" → AND;
- "unless" → usually a NOT.
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.
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.
- $D = 1$ means the door is open;
- $S = 1$ means the system is on;
- $P = 1$ means the emergency button is pressed.
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”.