Worked example · Computer Science · Year 7

Binary code bracelets

DCF: Data and computational thinking → Problem-solving and modelling

What this is

A completed Year 7 sheet, plus the full code for all 26 letters so you can mark any bracelet in the room in seconds. The scheme is: letter position in the alphabet (A = 1 … Z = 26), written in five binary digits with place values 16, 8, 4, 2, 1. A dark bead is a 1. Show this after pupils have designed their own bracelet.

Conversion practice, completed

LetterNumber5-bit codeWorking
A1000011 = 1
G7001114 + 2 + 1 = 7
L12011008 + 4 = 12
S191001116 + 2 + 1 = 19
Z261101016 + 8 + 2 = 26
T201010016 + 4 = 20, so it is letter 20, T
F6001104 + 2 = 6, so it is letter 6, F

The two bottom rows go backwards: 10100 has dark beads worth 16 and 4, so 16 + 4 = 20, and letter 20 is T. 00110 has dark beads worth 4 and 2, so 4 + 2 = 6, and letter 6 is F.

Place-value working shown both ways round, letter to bits and bits to letter — first and second success criteria.

The mystery bracelet, decoded

LetterBeadsAdding the dark beadsNumberLetter
1st001014 + 1 = 55E
2nd1001016 + 2 = 1818R
3rd1100116 + 8 + 1 = 2525Y
4th1001016 + 2 = 1818R
5th010018 + 1 = 99I

The word is ERYRI — the Welsh name for Snowdonia. The giveaway was that the 2nd and 4th letters have exactly the same bead pattern, so they had to be the same letter.

Decodes a pattern somebody else made, and uses a property of the code (repeated patterns mean repeated letters) as a strategy.

My own bracelet: CYMRU

LetterNumber5-bit codeWorking
C3000112 + 1 = 3. 16, 8 and 4 are all bigger than 3, so those beads are light.
Y251100116 + 8 = 24, then 4 and 2 are too big for the 1 that is left, so 16 + 8 + 1 = 25.
M130110116 is too big, so 8 + 4 = 12, then 2 is too big, then + 1 = 13.
R181001016 fits, leaving 2. 8 and 4 are too big, 2 fits exactly, so 16 + 2 = 18.
U211010116 fits, leaving 5. 8 too big, 4 fits leaving 1, 2 too big, 1 fits: 16 + 4 + 1 = 21.
Bracelet spelling CYMRU in five-bit binary 0 0 0 1 1 1 1 0 0 1 0 1 1 0 1 1 0 0 1 0 1 0 1 0 1 C = 3 Y = 25 M = 13 R = 18 U = 21 Filled bead = 1 · empty bead = 0 · red divider = end of a letter

My partner decoded it as CYMRU without being told, so the bracelet is correct.

The bracelet is drawn and then tested by a partner, which is the only way to know a code works — third success criterion.

How many patterns?

1. 32. Each bead can be one of two colours, so five beads give 2 × 2 × 2 × 2 × 2 = 2⁵ = 32 different patterns.

2. The largest number is 31, from the pattern 11111: 16 + 8 + 4 + 2 + 1 = 31. Note that 32 patterns but a largest value of 31 is not a mistake — one of the patterns, 00000, stands for 0.

3. Four beads only give 2⁴ = 16 patterns, and the alphabet needs 26. Ten letters would have no code at all, or two letters would have to share one, and then nobody could tell which was meant.

4. 32 patterns minus 26 letters leaves 6 spare (including 00000). You could use them for a space, a full stop, a comma, a question mark, and a marker for "the next letter is a capital". A space is the important one: without it the bracelet is one long word.

Counts the patterns from the doubling rule rather than by listing, and explains why 4 beads fail — fourth success criterion.

The problem I noticed

If I just thread 25 beads with nothing between them, the person decoding has to know that the letters are five beads long — and if they miscount once, every letter after that comes out wrong. That is why I put a thin red divider bead after each letter. Real computers do the same job by fixing the length: every character is exactly 8 bits, so the machine always knows where one ends and the next starts.

Spots that a code needs framing as well as symbols — fifth success criterion.

Extension: the 8-bit code

Place values are 128, 64, 32, 16, 8, 4, 2, 1.

Capital C is 67: 64 fits, leaving 3; 32, 16, 8 and 4 are all too big; 2 fits, leaving 1; 1 fits. So 64 + 2 + 1 = 67 and the code is 01000011.

Capital Y is 89: 64 fits, leaving 25; 32 too big; 16 fits, leaving 9; 8 fits, leaving 1; 4 and 2 too big; 1 fits. So 64 + 16 + 8 + 1 = 89 and the code is 01011001.

8 bits give 2⁸ = 256 patterns. A computer needs them for lower-case letters, the digits 0 to 9, punctuation, the space, symbols such as £ and @, and invisible control characters such as "new line" — none of which a 26-letter bracelet can show.

Extends the same place-value method to a longer code and justifies why the extra length is needed.

Teacher key — all 26 letters

LNo.CodeLNo.CodeLNo.CodeLNo.Code
A100001H801000O1501111V2210110
B200010I901001P1610000W2310111
C300011J1001010Q1710001X2411000
D400100K1101011R1810010Y2511001
E500101L1201100S1910011Z2611010
F600110M1301101T2010100
G700111N1401110U2110101

To check any bracelet: read the dark beads left to right as 16, 8, 4, 2, 1, add them up, and count that far into the alphabet.

Why this response is secure