
July 15th, 2003, 03:02 PM
|
 |
Contributing User
|
|
Join Date: Jan 2003
Location: USA
|
|
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:
Quote:
C:\dcw\PROJECTS\TEST\julian>od -x julian.c |head -4
0000000 6923 636e 756c 6564 3c20 7473 6c64 6269
0000020 682e 0d3e 230a 6e69 6c63 6475 2065 733c
0000040 6474 6f69 682e 0d3e 0d0a 760a 696f 2064
0000060 6552 6f70 7472 6928 746e 6920 6f48 7275
C:\dcw\PROJECTS\TEST\julian>xxd julian.c |head -4
0000000: 2369 6e63 6c75 6465 203c 7374 646c 6962 #include <stdlib
0000010: 2e68 3e0d 0a23 696e 636c 7564 6520 3c73 .h>..#include <s
0000020: 7464 696f 2e68 3e0d 0a0d 0a76 6f69 6420 tdio.h>....void
0000030: 5265 706f 7274 2869 6e74 2069 486f 7572 Report(int iHour |
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:
Code:
// dumps contents of EEROM
void HexDump(void)
{
int i, j;
BYTE byte, index;
char s[40];
char s1[10];
index = 0;
for (i=0; i<8; i++)
{
strcpy(s,"");
for (j=0; j<16; j++)
{
if (j && !(j%4))
strcat(s," ");
byte = EERomRead(index);
sprintf(s1,"%02X",byte);
strcat(s,s1);
index++;
}
printf("%s\n",s);
}
}
Last edited by dwise1_aol : July 15th, 2003 at 03:05 PM.
|