#include <stdio.h> typedef union{ unsigned short value; unsigned char byte[2]; }CodeOrderUnion; void test_endian() { CodeOrderUnion order; order.value = 0x0102; if(order.byte[0] == 0x01 && order.byte[1] == 0x02){ printf("Small Endian "); } else if(order.byte[0] == 0x02 && order.byte[1] == 0x01){ printf("Big Endian "); } else{ printf("error! "); } } int main() { test_endian(); }