byte order testing?

How can I test whether my system’s byte order is big endian or little endian.?

How can I convert from big to little endian?

2 Comments »

  1. KC said

    Little endian and Big Endian refer to the layout of byte in which the data is stored.

    Big endian : Stores most significant data of information from the base address.
    Little Endian : Stores from least significant data from the base address.

    let us take an example :

    I want to store 14 in an integer on a 32bit machine.

    in the binary pattern the number is represented as 1110.
    If the same is to be stored in a 32bit alignment.

    Big Endian stored it like :

    0000-0000 0000-0000 0000-0000 0000-1110

    Little Endian stores it like :
    0000-1110 0000-0000 0000-0000 0000-0000

    So the following program might help you in knowing whether your machine is of Little-Endian or Big Endian Architecture.

    void main()
    {
    int i = 1;
    char *c = (char *)&i;

    if ( *c == 1 )
    {
    cout< <" LITTLE ENDIAN";
    }
    else
    {
    cout< <" BIG ENDIAN";
    }
    }

  2. kiran kumar katreddi said

    Hoa about converting from little endian to big endian?

RSS feed for comments on this post · TrackBack URI

Leave a Comment