Why we need character coding
A computer only stores numbers, so every letter, digit and symbol must be given a number code before it can be saved or sent. A character code is an agreed table that matches each character to one number. The most common table for basic English text is ASCII (American Standard Code for Information Interchange).
Key idea
ASCII uses 7 bits, so it can represent 27 = 128 different characters, numbered 0 to 127.
Important ASCII values
- Capital 'A' = 65, so 'B' = 66, 'C' = 67 ...
- Small 'a' = 97, so 'b' = 98 ...
- Digit character '0' = 48, '1' = 49 ...
- Space = 32
Notice that a capital letter and its small letter are always 32 apart: 'a' − 'A' = 97 − 65 = 32.
Example
What is the ASCII code of 'E'? Since 'A' = 65 and E is the 5th letter, 'E' = 65 + 4 = 69. To turn the digit character '7' into its code: '0' = 48, so '7' = 48 + 7 = 55.
Codes are just numbers
Because each character is a number, the computer can store it in binary; for example 'A' = 65 = 10000012. Sorting words into alphabetical order works by comparing these codes.
Remember
- 'A' = 65, 'a' = 97, '0' = 48.
- Small letters have larger codes than capital letters.
- The digit character '0' is code 48, not 0.