What You Will Build
Build a binary number learning game where players convert decimal numbers using toggle buttons. Follow the guide below to build the project, then open the official Raspberry Pi page for starter files, worked examples and extra help.
🍓 This project is on the Raspberry Pi Foundation website. Click the orange button above to access the full guide, starter Scratch project and extension activities on projects.raspberrypi.org.
What You Will Learn
- Understand the binary number system and positional values (8, 4, 2, 1)
- Create toggle buttons that flip binary bits on and off
- Calculate the decimal value of the current binary selection
- Compare the player's answer to a randomly generated target number
- Track score and accuracy across 10 challenges
Step-by-Step Guide
- 1Add a tech-themed backdrop.
- 2Create a target: pick random 1 to 15 and store as target variable.
- 3Display target using show variable [target].
- 4Add 4 bit sprites labelled 8, 4, 2, 1. Each has on (lit) and off (dark) costumes.
- 5When bit sprite clicked: toggle costume between on/off and change a bit8/bit4/bit2/bit1 variable between 1 and 0.
- 6Add a total variable: total = (bit8×8) + (bit4×4) + (bit2×2) + bit1.
- 7Update total in a forever loop and display it.
- 8Add a Submit button. If total = target: score +10, play cheer, new target.
- 9If total ≠ target: play buzzer, flash the wrong bits in red.
- 10After 10 challenges: show score out of 100 and an accuracy percentage.
Extension Challenges
Finished the main project? Push further:
- Extend to 8-bit numbers (0–255) using 8 bit sprites for a harder mode.
- Add a hex conversion challenge: convert the binary to hexadecimal after getting it right.
- Add a timed mode where the player must answer within 10 seconds per question.