#include <stdio.h>
typedef union
{
unsigned short int value;
unsigned char byte[2];
}to;
int main(int argc, char *argv)
{
to typeorder;
typeorder.value = 0xabcd;
if (typeorder.byte[0] == 0xcd && typeorder.byte[1] == 0xab)
{
printf("Low endian byte order!\n");
}
if (typeorder.byte[0] == 0xab && typeorder.byte[1] == 0xcd)
{
printf("High endian byte order!\n");
}
return 0;
}
-----------------------------------------------------------------------
#define BIGGER_ORDER 1
#define LITTLE_ORDER 0
#define ERROR -1
typedef union
{
unsigned short int value;
unsigned char val[2];
}testoarder;
int test_code_order(void)
{
testorder temp;
temp.value = 0x1234;
if((temp.val[0] == 0x12) && (temp.val[1] == 0x34))
{
return BIGGER_OEDER;
}
else if((temp.val[0] == 0x34) && (temp.val[1] == 0x12))
{
return LITTLE_ORDER;
}
else
{
return ERROR;
}
}