The answersDownload the PDF
Worksheet

F8.2 Binary and denary

Data representation · GCSE · OCR J277 1.2.4, AQA 8525 3.3.1, Edexcel 1CP2 2.1.3 · about 15 min

BugBotLab
NameClassDate

What this lesson is about

Converting 8-bit numbers both ways, and hearing them on the buzzer.

Questions 6 marks in all

  1. [1 mark]What is 01001101 in denary?

  2. [1 mark]Write 200 as an 8-bit binary number.

  3. [1 mark]What is the largest number 8 bits can hold?

  4. [1 mark]Write 5 as an 8-bit binary number.

  5. [1 mark]What does this program print?

    total = 0
    value = 1
    for bit in reversed("1010"):
        if bit == "1":
            total = total + value
        value = value * 2
    print(total)
  6. [1 mark]What is the place value of the leftmost bit in an 8-bit binary number?

    1. A128
    2. B256
    3. C100
    4. D8

The task: play in binary

Write to_binary(n) yourself, without bin, format or int(..., 2), that returns an 8-character string of 1s and 0s. Use it to print the binary of 77, 5 and 200, one per line, and then play the bits of 77: a note of 880 Hz for each 1 and 440 Hz for each 0, each for 0.2 seconds.

# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()

def to_binary(n):
    return ""

Plan your program here, then type it in and press Run.

QR code
Do it on the robot
www.bugbotlab.com/learn/f8-2-binary-and-denary/
The simulator checks it and tells you when it passes. Nothing to install, no account.

Challenges

  1. How many bits are needed for the number 1,000? Write a loop that doubles until it passes 1,000.
  2. Convert your age to binary by hand, then check with your function.
  3. Write to_denary with the dividing-by-2 idea turned round: start from the left, and for each bit double the total and add the bit.