in reply to Datatype and pack/unpack

theantler:

It's not called ASCII because it's not an ASCII character. There's some history involved which makes the data type name a bit misleading. It's much like weight and mass in physics: A pound of mass weighs a pound of weight because we're on the surface of the earth. On the moon, the mass and weight are drastically different.

In early computer times, we would store a character in a byte. But even then, a character wasn't necessarily ASCII. If you write an 0x40 to most terminals, you'd get an "@" on the screen, because most terminals were ASCII. But if you wrote it to an EBCDIC terminal, you'd see a " " instead.

Think of it as an eight-bit signed integer rather than a graphic symbol.

...roboticus

Replies are listed 'Best First'.
Re^2: Datatype and pack/unpack
by theantler (Beadle) on Mar 19, 2010 at 18:24 UTC
    Thank you people, for all your responses. Ok, so the "char" is just en eight-bit integer and there is no necessity to what this range of numbers represent, then why does my computer produce ABCDE from the example code?  $pack = pack ('c4', 65, 66, 67, 68); When I "pack" 65 by using a char type, I get A .. WHY WHY WHY .. It is just an eight-bit int why does it HAVE to end as an A?
      As was mentioned above, The mapping of value 65 to the character "A", is just because you're using a computer that's configured for a character encoding that makes this true.

      If your machine was using EBCDIC, the value 65 would map to a Non-breaking Space.

      Your mapping of 65 to "A" is not much of a surprise because many modern character encodings are build as a superset of the 7 bit ASCII encoding. It's not uncommon to see folks using the "Latin" code pages that have this property, as does UTF-8. Any of these choices are common.

        Thanks .. I appreciate your kindness to take the time and respond.