Character Encoding
Computers only store numbers. So every letter, digit, and symbol needs an agreed number to represent it, otherwise your computer and mine might disagree on what a byte of text actually says. That agreement is a character encoding.
Look up a character
Type a single character and see its code in denary, binary, and hex all at once. ASCII covers the codes 0-127, more than enough for English letters, digits, punctuation, and a few control codes.
Type a character
Just the first character typed is used.
Printable ASCII reference (32-126)
Encoding a whole word
A string of text is just a sequence of individual character codes, stored one after another. Type a short word and see it broken apart.
Type a word
Exam tips
- A string's storage size in bytes is simply the number of characters, if each character uses 1 byte (as in ASCII).
- Spaces and punctuation each need their own code too, they're not free.
Proof: uppercase and lowercase differ by exactly 32
This is one of the most useful patterns in ASCII, and it's not a coincidence. Every lowercase letter's code is exactly 32 more than its uppercase equivalent, which means converting case is just addition or subtraction, not a lookup table.
Try a letter
Exam tips
- Uppercase to lowercase: add 32. Lowercase to uppercase: subtract 32.
- This only works within the same letter, 'A' + 32 = 'a', but it's not "add 32 to any code" for unrelated characters.
- Digits 0-9 have their own separate block of codes (48-57), also conveniently placed so that a digit character's code minus 48 gives its actual numeric value.
Beyond ASCII: why Unicode exists
ASCII's 128 codes (7 bits) cover English text, but the world's languages, symbols, and emoji need vastly more than 128 distinct characters. Unicode assigns a unique "code point" to every character from every writing system, and emoji too, some needing far more than 7 bits to represent.
Try a character
Exam tips
- ASCII: 7 bits, 128 characters, English-centric.
- Unicode: a much larger set of code points (over a million possible), covering virtually every writing system and symbol in use.
- UTF-8 is a common way of actually storing Unicode code points as bytes, using 1 byte for ASCII-range characters (staying compatible with old ASCII files) and more bytes for higher code points.
- The trade-off for supporting every language: some characters now need more storage than the 1 byte ASCII used for everything.