The answersDownload the PDF
Worksheet

F8.3 Hexadecimal

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

BugBotLab
NameClassDate

What this lesson is about

Base 16, converting to binary and denary, and the LED's colour codes.

Questions 6 marks in all

  1. [1 mark]Convert 10110110 to hexadecimal.

  2. [1 mark]What is hex 3F in denary?

  3. [1 mark]Convert 255 to hexadecimal.

  4. [1 mark]Why do programmers use hexadecimal?

    1. AIt is shorter and easier to read than binary, and easy to convert
    2. BComputers store data in hexadecimal
    3. CIt takes less memory
    4. DIt is more accurate than binary
  5. [1 mark]What colour is #00FF00 on the LED?

    1. AGreen
    2. BRed
    3. CBlue
    4. DWhite
  6. [1 mark]How many bits does one hex digit stand for?

The task: mix a colour

Write to_hex(n) yourself (no hex or format) that turns 0 to 255 into two hex digits. Use it to build the colour code for red 255, green 128, blue 64, print it as #FF8040, and show it on the LED by passing your code to led.

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

DIGITS = "0123456789ABCDEF"

def to_hex(n):
    return "00"

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

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

Challenges

  1. Write rgb(code) that turns "#FF8040" back into the three numbers.
  2. Fade the LED from black to white in 16 steps, printing each hex code.
  3. What is the largest number three hex digits can hold? Work it out, then check with int("FFF", 16).