Is there any logic behind ASCII codes’ ordering?

There are historical reasons, mainly to make ASCII codes easy to convert:

Digits (0x30 to 0x39) have the binary prefix 110000:

0 is 110000
1 is 110001
2 is 110010

So if you wipe out the prefix (the first two ‘1’s), you end up with the digit in binary coded decimal.

Capital letters have the binary prefix 1000000:

A is 1000001
B is 1000010
C is 1000011

Same thing, if you remove the prefix (the first ‘1’), you end up with alphabet-indexed characters (A is 1, Z is 26, etc).

Lowercase letters have the binary prefix 1100000:

a is 1100001
b is 1100010
c is 1100011

Same as above. So if you add 32 (100000) to a capital letter, you have the lowercase version.

Leave a Comment