2.2.1 ASCII character encoding
What Is ASCII?
ASCII (American Standard Code for Information Interchange) is a character encoding standard that assigns a unique 7-bit binary code to each of 128 characters. It was developed in the 1960s and became the foundation for modern text representation in computers.
Using 7 bits gives 27 = 128 different codes (0–127). These cover:
- Uppercase letters A–Z (codes 65–90)
- Lowercase letters a–z (codes 97–122)
- Digits 0–9 (codes 48–57)
- Punctuation and symbols (!, @, £, #, etc.)
- Control characters (e.g. newline, tab, carriage return)
Key ASCII Values to Know
| Character | Denary | Binary (7-bit) | Hex |
|---|---|---|---|
| A | 65 | 1000001 | 41 |
| B | 66 | 1000010 | 42 |
| Z | 90 | 1011010 | 5A |
| a | 97 | 1100001 | 61 |
| z | 122 | 1111010 | 7A |
| 0 | 48 | 0110000 | 30 |
| 9 | 57 | 0111001 | 39 |
| Space | 32 | 0100000 | 20 |
Key patterns to remember
- Uppercase letters start at 65 (A). Each subsequent letter adds 1: B=66, C=67, ...
- Lowercase letters start at 97 (a). The difference between any uppercase and its lowercase is always 32: a = A + 32.
- Digit characters start at 48 ('0'). The digit character '5' is code 48+5 = 53.
- The character '0' (code 48) is not the same as the number 0 (which has no ASCII character representation in the printable set).
ASCII in Practice
When text is stored in memory or a file, each character is stored as its ASCII code in binary. The word "Hi" is stored as two bytes:
- 'H' = 72 =
01001000 - 'i' = 105 =
01101001
In Python, ord("A") returns the ASCII code of a character (65) and chr(65) returns the character for a given code ("A"). These are PLS-supported built-in functions.
ASCII uses 7 bits, leaving the 8th bit free. Extended ASCII systems used this extra bit to add 128 more characters (accented letters, box-drawing symbols) — but this was non-standard. Unicode was later developed to represent the characters of all the world's writing systems.
Key Takeaways
- ASCII encodes 128 characters using 7-bit binary codes (0–127).
- A=65, a=97 — the difference between uppercase and lowercase is always 32.
- Digit characters '0'–'9' have codes 48–57 — not the same as the numeric values 0–9.
- Text is stored as a sequence of ASCII codes; each character = one byte.