How are ASCII characters stored in memory?
Consider a computer that has a byte add开发者_开发技巧ressable memory organized in 32 bit words according to the big endian scheme. A program reads ASCII characters entered at a keyboard and stores them in successive byte locations, starting at location 1000. Show the contents of two memory words at locations 1000 and 1004 after the name "johnson" has been entered.
Just convert each letter to hex using a handy ASCII table, and add them to memory sequentially. This renders easily as gorgeous ASCII graphics:
+------+--+--+--+--+
|0x1000|6A|6F|68|6E|
+------+--+--+--+--+
The last four bytes were left out, this is homework after all.
There is no such thing as endianes for storing a single byte (such as an ASCII character). Endianes only comes into play when a value is represented as multiple bytes. So for example, storing a sequence of bytes is the same in little- and big-endian, only the representation of the bytes are different. For example, take the number 3 735 928 559 (or 0xdeadbeef in hex notation) and store that as a 32-bit word (e.g., an int) at memory location 1000 will give:
ADR: 1000 1001 1002 1004
BE: de ad be ef
LE: ef be ad de
I think than words will have next values:
1000: 0x6a6f686e
1004: 0x736f6e00
'Cause of name contains only 7 characters, eight character is unknown, so last position (00) may have any value.
1000: 0x6a 6f 68 6e
j o h n
1004: 0x73 6f 63 00
s o n NULL
精彩评论