tags:

views:

733

answers:

8

Hi,

I was teaching C to my younger brother studying engineering. I was explaining him how different data-types are actually stored in the memory. I explained him the logistics behind having signed/unsigned numbers and floating point bit in decimal numbers. While I was telling him about char type in C, I also took him through the ASCII code system and also how char is also stored as 1 byte number.

He asked me why 'A' has been given ascii code 65 and not anything else ? Similarly why 'a' is given the code 97 specifically ? Why there's a gap of 6 ascii codes between the range of capital letters and small letters ? I had no idea of this. Can you help me understand this, since this has created a great curiosity to me as well. I've never found any book so far that has discussed this topic.

What is the reason behind this ? Are ASCII codes logically organized ?

+1  A: 
  • '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 for A, a and 0-9. I have no idea about the symbols. See The Wikipedia article on ASCII Ordering.

too much php
that is the question. Everybody knows the ASCII table. I also infact checked if there's any ordering logic in HEX, but I didn't find any. And no book [I've read so far] has ever covered this.
this. __curious_geek
Posts with "I have no idea" in it shouldn't be posted, should they ?
Clement Herreman
+5  A: 

Here is very detailed history and description of ASCII codes: http://en.wikipedia.org/wiki/ASCII
In short:

  • 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:
    • space,
    • upper case sign on number caps: !, ", #, ...,
    • numbers
    • 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
zendar
Some older keyboards (I know the Atari 800 was one) had the " character on the 2 key, so the correspondence between encoding and keyboard order was closer.
dan04
+2  A: 

The distance between A and a is 32. That's quite round number, isn't it?

The gap of 6 characters between capital letters and small letters is because (32 - 26) = 6. (Note: there are 26 letters in the English alphabet).

Grzegorz Oledzki
The English alphabet has 26 characters if you are making naïve assumptions about borrowed words.
Rich Seller
Actually ï is the same letter as i but with a diacritical mark. And while English borrowed quite a few words I don't think it borrowed letters like þ (Icelandic) or IJ (Dutch).
MSalters
A: 

If you look at the binary representations for 'a' and 'A', you'll see that they only differ by 1 bit, which is pretty useful (turning upper case to lower case or vice-versa is just a matter of flipping a bit). Why start there specifically, I have no idea.

Tal Pressman
+5  A: 
Adrian
+40  A: 

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

etc. So if you wipe out the prefix (the first two '1'), 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

etc. Same thing, if you remove the prefix (the first '1'), you end up with alphabet-indexed characters.

Lowercase letters have the binary prefix 1100000:

a is 1100001
b is 1100010
c is 1100011

etc. Same as above.

FWH
Interesting.. I never noticed it.
Naveen
brilliant find.
this. __curious_geek
A: 

@Carsten Ehrler: Hmm. If you have a Linux system, do a

man ascii

Can't assume an ordering of numerals? No logic? What kind of dope are you smoking, and where can I get some?

xcramps
A: 

Wikipedia:

The code itself was structured so that most control codes were together, and all graphic codes were together. The first two columns (32 positions) were reserved for control characters.[14] The "space" character had to come before graphics to make sorting algorithms easy, so it became position 0x20.[15] The committee decided it was important to support upper case 64-character alphabets, and chose to structure ASCII so it could easily be reduced to a usable 64-character set of graphic codes.[16] Lower case letters were therefore not interleaved with upper case. To keep options open for lower case letters and other graphics, the special and numeric codes were placed before the letters, and the letter 'A' was placed in position 0x41 to match the draft of the corresponding British standard.[17] The digits 0–9 were placed so they correspond to values in binary prefixed with 011, making conversion with binary-coded decimal straightforward.

beggs