AQA GCSE Computer Science June 2025 Paper 1, Question 8: tracing two binary strings
AQA 8525 June 2025 Paper 1, Question 8: trace a loop that compares the strings 0010 and 0111 character by character with OR, NOT and AND, building a new string. The full table, why the loop stops at LEN minus 1, and the algorithm to run.
Question 8 of the AQA GCSE Computer Science Paper 1 sat on 12 May 2025 (8525/1B, the Python paper) is a 5 mark trace table, with one more mark for explaining the end of the loop. The algorithm looks fierce, with a nested IF and three Boolean operators, and it turns out to do something simple.
We do not copy the exam paper here. Open it beside this page: AQA June 2025 Paper 1B question paper (PDF). When you have finished, check the mark scheme too.
The question in short
Two strings: b1 is '0010' and b2 is '0111'. new starts empty.
A loop runs i from 0 to LEN(b1) - 1. For each position it looks at the two characters:
- if either is '1', it goes on to ask whether they are not both '1'. If so it adds '1' to
new. If they are both '1' it adds '0'; - if neither is '1', it adds '0'.
After the loop it outputs new.
Boil it down
It adds '1' when exactly one of the two characters is '1', and '0' when they are the same. That is all. (It is the logic operation called exclusive OR, or XOR.)
Work it through
| i | b1[i] | b2[i] | Exactly one is 1? | new |
|---|---|---|---|---|
| 0 | 0 | 0 | no | '0' |
| 1 | 0 | 1 | yes | '01' |
| 2 | 1 | 1 | no (both) | '010' |
| 3 | 0 | 1 | yes | '0101' |
The finished trace table
| b1 | b2 | new | i |
|---|---|---|---|
| '0010' | '0111' | '' | |
| '0' | 0 | ||
| '01' | 1 | ||
| '010' | 2 | ||
| '0101' | 3 |
The five marks: b1 and b2 written once each, with nothing else in their columns; i starting at 0; the rest of i (1, 2, 3); the first value of new; the rest of new. Quotation marks are optional. Any error caps it at 4.
Part 2: why LEN(b1) - 1?
The string has 4 characters, and indexing starts at 0, so the last one is at position 3. LEN(b1) is 4, and there is no character at position 4. Looping to LEN(b1) - 1 stops the algorithm trying to use an index that is out of range.
Where the marks are lost
- Replacing
newand not building it.new ← new + '1'adds to the end. The column grows: '0', '01', '010', '0101'. - '1' at position 2. Both characters are '1', so the inner test fails and '0' is added.
- Doing arithmetic. 0010 + 0111 as binary addition is 1001. This algorithm never adds numbers. The
+joins strings. - Five passes.
istops at 3. - Rewriting
b1andb2on every row. They never change.
Run it
The algorithm in Python, printing a row for each pass. Change the two strings. Python's own XOR operator, ^, is used at the end to check the answer.
The program
from bugbot import *
connect()
b1 = "0010"
b2 = "0111"
new = ""
print("i b1[i] b2[i] new")
for i in range(0, len(b1)):
if b1[i] == "1" or b2[i] == "1":
if not (b1[i] == "1" and b2[i] == "1"):
new = new + "1"
else:
new = new + "0"
else:
new = new + "0"
print(i, b1[i], b2[i], new)
print(new)
check = int(b1, 2) ^ int(b2, 2)
print("XOR check:", format(check, "04b"))
Questions
What is the answer to AQA GCSE Computer Science 2025 Paper 1 Question 8.1?
i goes 0, 1, 2, 3. new goes from the empty string to '0', '01', '010' and '0101'. b1 and b2 do not change.
Why does the loop go to LEN(b1) - 1?
Because string indexing starts at 0, the last character of a 4 character string is at index 3. Using index 4 would try to read a character that does not exist.
What is XOR?
Exclusive OR. Its output is 1 when exactly one of its two inputs is 1, and 0 when they are the same. It can be built from OR, AND and NOT: (A OR B) AND NOT (A AND B).
More from this paper
Every AQA 8525 question we have worked · Guide: Logic gates and truth tables explained
Learn it step by step
- F13.2 Trace tables Exam preparation
- F3.1 String handling Strings, lists and records
- F2.3 else, elif and Boolean operators Decisions and loops
This is our own explanation of a published exam question. It is not written or endorsed by AQA, and the question paper and mark scheme remain AQA's copyright. Read them on AQA's site with the links on this page.