Character sets, and why ASCII was not enough
A-Level Computer Science · Data Representation: Number Bases, Binary Arithmetic and Character Sets
A character set is an agreement
A computer stores only numbers, so text needs a table mapping each character to a code. ASCII uses $7$ bits, giving $128$ codes — enough for English letters, digits and punctuation. Extended ASCII uses $8$ bits for $256$.
Two facts about ASCII worth knowing
The codes are contiguous and ordered: 'A' is $65$, so 'C' is $67$; 'a' is $97$, exactly $32$ more than 'A'. That gap of $32$ is one bit, which is why changing case is a single bit operation. Digit '0' is $48$, so the character '7' minus $48$ gives the number $7$ — the standard way to convert a digit character to its value.
Why Unicode
$256$ codes cannot hold Vietnamese, Chinese, Arabic, Greek and emoji at the same time. Unicode gives every character in every writing system a unique code point. UTF-$8$ stores them in one to four bytes, and is designed so that the first $128$ code points are byte-identical to ASCII — old files still work.
The trade-off
Unicode text takes more storage than ASCII for the same message. That is the price of covering every language, and it is the comparison Cambridge asks for.
Worked example: using the contiguity of the character set
Given that the ASCII code of 'A' is $65$ and of 'a' is $97$.
(a) Calculate the codes of 'F' and 'f'. (b) Write an expression that converts any uppercase letter to the corresponding lowercase letter. (c) Explain why ASCII is not enough for Vietnamese.
Solution
(a) 'F' is the sixth letter so its code $= 65 + 5 = 70$. A lowercase letter is exactly $32$ more than the uppercase one, so 'f' $= 70 + 32 = 102$.
(b) $\text{lower\_code} = \text{upper\_code} + 32$. In other words, set the sixth bit (value $32$) to $1$, which is why many processors change case with an OR with $00100000$.
(c) Vietnamese needs accented letters such as a with a breve, o with a horn, e with a circumflex and a dot below, and u with a horn and a tilde. The Vietnamese alphabet alone has $29$ letters, and with five tone marks placed on many different vowels, the total number of characters needed far exceeds the space left in ASCII's $128$ codes. Not to mention that if a document also contains Chinese or emoji, the $256$ codes of Extended ASCII are not enough either. Unicode solves this by giving every character of every writing system its own code point.