GoalExplain what a character set is and use ASCII codes to turn text into binary and back.
New words
character set · a list of characters, each with its own binary codeASCII · a character set that uses 7 bits for each code, which gives 128 charactersextended ASCII · ASCII with 8 bits, which gives 256 characters
Explanation
A computer can only store binary, so each letter, digit and symbol must have a binary code. A character set is a list of all the characters with their codes. ASCII is a well-known character set. It uses 7 bits for each of 128 characters, such as English letters, the digits 0 to 9 and symbols. Extended ASCII uses 8 bits, so it has 256 characters, which is room for more symbols. Capital H has a different code from small h, because they are different characters. The character “7” has the code 55, which is not the same as the number 7 you can calculate with. To turn text into binary, find each character’s code in the table, then write the code as 8 bits.
Characters
ASCII codes (denary)
A, B, C … Z
65, 66, 67 … 90
a, b, c … z
97, 98, 99 … 122
"0", "1" … "9"
48, 49 … 57
Worked examples
Character
Code
Binary
H
72
01001000
i
105
01101001
Write “Hi” in binary. H is 72 and i is 105. Convert each: 72 = 64 + 8 gives 01001000, and 105 = 64 + 32 + 8 + 1 gives 01101001. So “Hi” is 01001000 01101001.
Binary
Denary
Character
01110100
116
t
01100101
101
e
01100001
97
a
Now read a message back. A computer stores 01110100 01100101 01100001. These are 116, 101 and 97. Letters follow each other in the code, and a is 97, so 101 is e and 116 is t. The word is tea.
Character
Denary
Binary
R
82
01010010
r
114
01110010
Capital letters and small letters have different codes. R is 82 and r is 114. A program that compares “R” and “r” sees two different characters, so “Rita” and “rita” are different strings.
Class activity
Secret numbers (no computer). Use this table of letters and their numbers: A = 65, B = 66 and so on up to Z = 90, then a = 97 up to z = 122, and the digit characters “0” = 48 up to “9” = 57. Choose a three-letter word, write the ASCII number of each letter, then write each number as 8 bits. Give the 24 bits to a partner, who must decode them. Try again with one capital and two small letters. Why does your partner need the same table as you? Extend: write the code for the character “5”. Is it 5 in binary? Why not?
Practice
1
Use these codes: P = 80, Q = 81, R = 82. Write the binary for Q and R.