Sequential character codes

Character Codes Run in Sequence

Character codes are not assigned randomly. Within each group of related characters, the codes are consecutive - each character has a code exactly one higher than the character before it. This deliberate design means that if you know the code for one character in a group, you can calculate the code for any other character in the same group simply by counting forwards or backwards.

This sequential arrangement also means that characters are organised into distinct groups. The three most important groups to know are the digit characters, the uppercase letters, and the lowercase letters. Each group occupies a continuous, unbroken range of codes.

The Three Main Groups

The table below shows how each group occupies its own consecutive range of character codes. Notice that the groups do not overlap, and there are deliberate gaps between them.

Digit Characters: codes 48 to 57

The digit characters 0 through 9 occupy codes 48 to 57. These are the characters you type on a keyboard - they are not the same as the numbers 0-9 stored as raw integer values. Each digit is exactly one code higher than the previous one.

Character0123456789
Code48495051525354555657

Because the codes are sequential, a computer can check whether a character is a digit simply by testing whether its code falls in the range 48 to 57.

Uppercase Letters: codes 65 to 90

The 26 uppercase letters A through Z occupy codes 65 to 90. They run in strict alphabetical order, so A has the lowest code in the group and Z has the highest.

CharacterABCDE...XYZ
Code6566676869...888990

The sequential order makes it possible to determine the position of a letter in the alphabet: subtract 64 from its code. For example, E has code 69, and 69 - 64 = 5, confirming it is the 5th letter.

Lowercase Letters: codes 97 to 122

The 26 lowercase letters a through z occupy codes 97 to 122. They mirror the uppercase group exactly, but start at a higher code value. The gap between the start of the uppercase group (65) and the start of the lowercase group (97) is exactly 32.

Characterabcde...xyz
Code979899100101...120121122

Because the gap between the uppercase and lowercase versions of the same letter is always 32, a computer can switch between upper and lowercase by simply adding or subtracting 32 from the character code.

Why Sequential Grouping Matters

The sequential arrangement of character codes has two important practical benefits. First, it makes sorting straightforward: because the code for "A" is lower than the code for "B", a computer can sort words into alphabetical order simply by comparing character codes numerically, without needing any special knowledge of the alphabet itself. Second, it allows arithmetic on characters: because codes within a group are consecutive, adding or subtracting a number from a code moves predictably to another character in the group.

The Need for a Far Greater Range: Unicode

The grouping and sequential structure described above works well for English text, but the world uses many different writing systems. Languages such as Russian, Arabic, Greek, Hindi, Chinese, and Japanese each have their own alphabets or character sets, containing hundreds or thousands of unique characters. In addition, modern computing requires a vast range of special symbols - including mathematical notation, currency signs, and emoji - none of which appear in the basic 128-character ASCII set.

This is why Unicode was developed. Unicode applies the same principle of grouping and sequential code assignment, but across a far greater range of code points - currently over 140,000. Each world alphabet is assigned its own group within the Unicode standard, and within each group the characters run in sequence, just as they do in ASCII. This allows a single document to contain text from multiple languages simultaneously, something that would be impossible with ASCII alone.

Key principle: Unicode does not replace the idea of grouped, sequential character codes - it extends it to cover the full range of human writing systems and symbols.

 Key Takeaways

  • Character codes are not random - within each group, they run in sequence, with each character having a code exactly one higher than the previous character.
  • The three main groups are: digit characters (codes 48-57), uppercase letters (codes 65-90), and lowercase letters (codes 97-122).
  • Sequential codes make alphabetical sorting possible: a computer compares character codes numerically, and the correct alphabetical order follows automatically.
  • The uppercase and lowercase versions of the same letter always differ by exactly 32 in their character codes.
  • ASCII covers only basic English characters; many world alphabets and special symbols require a far greater range of codes, which is why Unicode was developed.
  • Unicode extends the same principle of grouped, sequential codes to cover over 140,000 characters across all major world writing systems.