July 15th, 2003, 01:50 PM
i always think i have this down pat, and then something confuses me, in this example:
i am storing 2 variables, x="ABCDEFGH" and y = 0xdeadbeef. how come deadbeef is stored normally, and ABCDEFGH is backwards? also, an even dumber question since im so confused: in the above example, when numbering the bytes we go from left to right, but with each group of 4 bytes we go from right to left, yes? so, teh byte @ address 0xbffffa40 is 01, correct?
Last edited by infamous41md; July 15th, 2003 at 02:04 PM.
July 15th, 2003, 03:02 PM
Your confusion may just be an artifact of the method you used to display that data. Assuming that you are on an Intel platform, if you had told it to output a long int in hex format, then it would have switched the bytes around accordingly.
Are you able to apply your favorite hex-dump utility to this data? Notice what happens when I apply od -x and then xxd to the same source file:
Notice how the 4-hex-digit displays in od are switched around from what they are in xxd? I believe that od is taking two bytes at a time, interpreting them as a short int, and displaying that value in hex. OTOH, xxd is taking it one byte at a time and displaying it in its proper order.
Here's a sample routine for printing a string of bytes out in hex:
// dumps contents of EEROM
int i, j;
BYTE byte, index;
index = 0;
for (i=0; i<8; i++)
for (j=0; j<16; j++)
if (j && !(j%4))
byte = EERomRead(index);
Last edited by dwise1_aol; July 15th, 2003 at 03:05 PM.