<"In computing, endianness is the ordering of individually addressable sub-units (words, bytes, or even bits) within a longer data word stored in external memory. The most typical cases are the ordering of bytes within a 16-, 32-, or 64-bit word, where endianness is often simply referred to as byte order.[1] The usual contrast is between most versus least significant byte first, called big-endian and little-endian respectively. Mixed forms are also possible; the ordering of bytes within a 16-bit word may be different from the ordering of 16-bit words within a 32-bit word, for instance; although fairly rare, such cases exist, and may sometimes be referred to as mixed-endian or middle-endian.

Endianness may be seen as a low-level attribute of a particular representation format, for example, the order in which the two bytes of an UCS-2 character are stored in memory. Byte order is an important consideration in network programming, since two computers with different byte orders may be communicating. Failure to account for varying endianness when writing code for mixed platforms can lead to bugs that can be difficult to detect."  wikipedia

Often I develop code that will run on different systems (680×0, PowerPC, Intel, ARM). When this code uses low level functions I need to make attention at the endianness, so I use the following piece of code to test the endianness:

#define     BE    1

#define     LE    0

 

char endian(void)

{

    short    x = 0x0100;

    return(*(char *)&x);

}

 

#define isBigEndian      (endian()==BE)

#define isLittleEndian   (endian()==LE)

 

The following code shows how to use the above function and MACROS:

#include <stdio.h>

#include <stdlib.h>

#include <unistd.h>

 

#define     BE    1

#define     LE    0

 

char endian(void)

{

    short    x = 0x0100;

    return(*(char *)&x);

}

 

#define isBigEndian      (endian()==BE)

#define isLittleEndian   (endian()==LE)

 

void doBigEndian(void)

{

    printf("Your processor is Big Endian\n");

}

 

void doLittleEndian(void)

{

    printf("Your processor is Little Endian\n");

}

 

void Uhu(void)

{

    printf("What kind of processor are you using?\n");

}

 

 

int main(void)

{

    if (isBigEndian)

    {

        doBigEndian();

    }

    else if (isLittleEndian)

    {

        doLittleEndian();

    }

    else

    {

        Uhu();

    }

}

 

Gg1