Data representation · GCSE · OCR J277 1.2.4, AQA 8525 3.3.2, Edexcel 1CP2 2.1.6 · about 15 min
Base 16, converting to binary and denary, and the LED's colour codes.
[1 mark]Convert 10110110 to hexadecimal.
[1 mark]What is hex 3F in denary?
[1 mark]Convert 255 to hexadecimal.
[1 mark]Why do programmers use hexadecimal?
[1 mark]What colour is #00FF00 on the LED?
[1 mark]How many bits does one hex digit stand for?
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.
rgb(code) that turns "#FF8040" back into the three numbers.int("FFF", 16).