Representing Text, Sound, Images and Storage: Question 6
Syllabus 1.2, 1.3
A retro text-adventure game stores its dialogue as plain text, using a custom character set that contains exactly 256 different symbols (letters, digits, punctuation and a few special game symbols).
(a) State the minimum number of bits needed to represent each of the 256 symbols in this character set, showing how you arrived at your answer. [2]
(b) One screen of dialogue contains 300 characters. Calculate the file size of this screen, in bytes. [2]
(c) The game contains 400 screens of dialogue, each exactly 300 characters long. Calculate the total file size of all the dialogue, in kilobytes (kB), using 1 kB = 1000 bytes. [3]
(d) State one advantage of using this 256-symbol character set, rather than Unicode (which can use up to 32 bits per character), for storing this game's dialogue. [1]
Show worked solution Hide worked solution
Worked solution
Part (a): Minimum bits needed for 256 symbols
Every different symbol in a character set must be given its own unique binary pattern, so the number of bits used must be large enough to produce at least as many different patterns as there are symbols. With n bits, 2^n different patterns can be made.
Try increasing values of n:
2^7 = 128, not enough, since the character set has 256 symbols.2^8 = 256, exactly enough to give every one of the 256 symbols its own unique pattern.
So the minimum number of bits needed is 8 bits (which is conveniently exactly 1 byte).
Part (b): File size of one screen of dialogue
Each character uses 8 bits, so the file size in bits is:
characters x bits per character = 300 x 8 = 2400 bits
Converting bits to bytes by dividing by 8:
2400 / 8 = 300 bytes
(This also matches the shortcut that, since each character is exactly 1 byte here, the file size in bytes simply equals the number of characters.)
So one screen of dialogue is 300 bytes.
Part (c): Total file size of all the dialogue, in kB
The game has 400 screens, each 300 bytes:
total bytes = 300 x 400 = 120,000 bytes
Converting to kilobytes using the decimal definition given in the question, 1 kB = 1000 bytes:
120,000 / 1000 = 120
So the total file size of all the dialogue is 120 kB.
Part (d): Advantage of the 256-symbol character set over Unicode
This character set only needs 8 bits per character, while Unicode can use up to 32 bits per character. Because each character takes up far fewer bits, dialogue text files stored using this 256-symbol character set are much smaller than the same text stored using Unicode, so they use less storage space and can be transferred or loaded more quickly. The trade-off is that a 256-symbol set cannot represent anywhere near as many different characters or scripts as Unicode.
Final answers
- (a) Minimum bits needed = 8 bits
- (b) File size of one screen = 300 bytes
- (c) Total file size of all dialogue = 120 kB
- (d) Smaller character set uses fewer bits per character than Unicode, so dialogue files are smaller and faster to load/transfer.