Tuesday, May 15, 2012

Endian

  • Register (device) and the host side main memory data (byte) transfer order.
  • Big/Little endian machine
  • If the system (machine) takes MSB of data first, then put in lower memory address, it is Big Endian machine.
  • Big: this looks normal way if addressing is increasing from left to right (just on the paper).

i.e.
If data in the register is (msb) 0x11223344 (lsb), location of each byte in the memory
(<-low) 11223344 (high->)


    • Little: this looked flipped way in the memory. (<-low) 44332211 (high->)



    But in the code:
    unsined int value;
    high <- value -> low
    Variable stored data as it is:
    value = 0x11223344 ==> Little



    #include <stdio.h>
    int main()
    {
    unsigned int i = 1;
    char *ptr;


    ptr = (char *) &i;

    if (*ptr)
    printf("Little\n");
    else
    printf("Big\n");

    return 0;
    }


    On Linux PC, it prints Little
    On IBM PowerPC it prints Big.




    Example:
    Intel: Little
    Motrola, IBM (powerPC): Big

    No comments:

    Post a Comment