Data representation · GCSE · OCR J277 1.2.4, AQA 8525 3.3.5, Edexcel 1CP2 2.2.1 · about 12 min
Character sets, bits per character, and why Unicode was needed.
[1 mark]How many characters can 7-bit ASCII represent?
[1 mark]Why was Unicode needed?
[1 mark]ord('A') is 65. What is ord('D')?
[1 mark]A 12-character message is stored in 7-bit ASCII. How many bits is it?
[1 mark]What does this program print?
print(len("robot".encode("utf-8")), len("机器人".encode("utf-8")))5 9
ASCII letters take 1 byte each in UTF-8; these Chinese characters take 3 each.
For the message BugBot says hi, print three lines: characters: <n>, ascii bits: <n> for 7-bit ASCII, and utf-8 bytes: <n>. Then print the 7-bit binary code of each of its first three characters, one per line, such as B 1000010. Work everything out from the message.
# the two lines every program starts with: the commands, then the robot from bugbot import * connect() message = "BugBot says hi"
The hint students can ask for: Count the characters for the first line, multiply by the bits per character for the second, and ask the encoded form for its length for the third. Then take each of the first three characters, find its code number and show it as seven binary digits.
from bugbot import *
connect()
message = "BugBot says hi"
print("characters:", len(message))
print("ascii bits:", len(message) * 7)
print("utf-8 bytes:", len(message.encode("utf-8")))
for ch in message[:3]:
print(ch, format(ord(ch), "07b"))
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.