1. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Rep Power

    big/little endian

    i always think i have this down pat, and then something confuses me, in this example:
    0xbffffa40: 0x00000001 0x00000000 0x4201581e 0xdeadbeef
    0xbffffa50: 0x44434241 0x48474645 0x4c4b4a49 0x504f4e4d
    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 01:04 PM.
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Rep Power
    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:
    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:
    // 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++)
            for (j=0; j<16; j++)
                if (j && !(j%4))
                    strcat(s," ");
                byte = EERomRead(index);
    Last edited by dwise1_aol; July 15th, 2003 at 02:05 PM.

IMN logo majestic logo threadwatch logo seochat tools logo