ASCII
ASCII is a 7-bit character code mapping 128 values to letters, digits, punctuation, and control codes.
The standard
ASCII, the American Standard Code for Information Interchange, assigns each of 128 codes (0–127) a meaning. It fits in 7 bits, and in practice occupies one byte with the top bit clear.
Structure
Codes 0–31 and 127 are non-printing control characters such as newline and tab. Codes 32–126 are printable: space, punctuation, digits 0–9, uppercase A–Z, and lowercase a–z.
Useful patterns
The layout is deliberately regular. Uppercase and lowercase letters differ by exactly one bit (value 32), so case can be flipped by toggling that bit. Digit characters '0'–'9' are contiguous starting at 48, so subtracting 48 yields the numeric value.
Limits
ASCII covers only English. Accented letters, other scripts, and symbols do not fit in 128 codes, which led to many incompatible 8-bit extensions and eventually to Unicode.
Legacy and compatibility
ASCII remains the foundation of text interchange: UTF-8 was designed so that the first 128 code points are byte-for-byte identical to ASCII, making plain English text valid in both.
| Char | Decimal | Hex |
|---|---|---|
| 'A' | 65 | 0x41 |
| 'a' | 97 | 0x61 |
| '0' | 48 | 0x30 |
| space | 32 | 0x20 |
print(ord('A'), chr(65)) # 65 A
print(chr(ord('A') | 0x20)) # 'a' toggle case bit