[ACCEPTED]-Is there any logic behind ASCII codes' ordering?-ascii
There are historical reasons, mainly to 12 make ASCII codes easy to convert:
Digits 11 (0x30 to 0x39) have the binary prefix 110000:
0 is 110000 1 is 110001 2 is 110010
etc. So 10 if you wipe out the prefix (the first two 9 '1's), you end up with the digit in binary 8 coded decimal.
Capital letters have the binary 7 prefix 1000000:
A is 1000001 B is 1000010 C is 1000011
etc. Same thing, if you remove 6 the prefix (the first '1'), you end up with 5 alphabet-indexed characters (A is 1, Z is 4 26, etc).
Lowercase letters have the binary 3 prefix 1100000:
a is 1100001 b is 1100010 c is 1100011
etc. Same as above. So if 2 you add 32 (100000) to a capital letter, you 1 have the lowercase version.
This chart shows it quite well from wikipedia: Notice 7 the two columns of control 2 of upper 2 6 of lower, and then gaps filled in with misc.
Also 5 bear in mind that ASCII was developed based 4 on what had passed before. For more detail 3 on the history of ASCII, see this superb article by Tom Jennings, which also 2 includes the meaning and usage of some of 1 the stranger control characters.
Here is very detailed history and description 1 of ASCII codes: http://en.wikipedia.org/wiki/ASCII
- ASCII is based on teleprinter encoding standards
- first 30 characters are "nonprintable" - used for text formatting
- then they continue with printable characters, roughly in order they are placed on keyboard. Check your keyboard:
- upper case sign on number caps: !, ", #, ...,
- signs usually placed at the end of keyboard row with numbers - upper case
- capital letters, alphabetically
- signs usually placed at the end of keyboard rows with letters - upper case
- small letters, alphabetically
- signs usually placed at the end of keyboard rows with letters - lower case
The distance between
a is 32. That's 4 quite round number, isn't it?
The gap of 3 6 characters between capital letters and 2 small letters is because (32 - 26) = 6. (Note: there 1 are 26 letters in the English alphabet).
- 'A' is 0x41 in hexidecimal.
- 'a' is 0x61 in hexidecimal.
- '0' thru '9' is 0x30 - 0x39 in hexidecimal.
So at least it is easy to remember the numbers 2 for
0-9. I have no idea about the symbols. See 1 The Wikipedia article on ASCII Ordering.
If you look at the binary representations 5 for 'a' and 'A', you'll see that they only 4 differ by 1 bit, which is pretty useful 3 (turning upper case to lower case or vice-versa 2 is just a matter of flipping a bit). Why 1 start there specifically, I have no idea.
The code itself was structured so that most 21 control codes were together, and all graphic 20 codes were together. The first two columns 19 (32 positions) were reserved for control 18 characters. The "space" character 17 had to come before graphics to make sorting algorithms 16 easy, so it became position 0x20. The 15 committee decided it was important to 14 support upper case 64-character alphabets, and 13 chose to structure ASCII so it could easily 12 be reduced to a usable 64-character set of 11 graphic codes. Lower case letters 10 were therefore not interleaved with upper 9 case. To keep options open for lower case 8 letters and other graphics, the special 7 and numeric codes were placed before the 6 letters, and the letter 'A' was placed 5 in position 0x41 to match the draft of the 4 corresponding British standard. The 3 digits 0–9 were placed so they correspond 2 to values in binary prefixed with 011, making conversion 1 with binary-coded decimal straightforward.
More Related questions