/* 本地字节序判断 */ #include <stdio.h> #include <stdlib.h> int main() { union { short s; char c[sizeof(short)]; }un; un.s = 0x0102; if (un.c[0] == 0x01 && un.c[1] == 0x02) { printf("Big-Endian "); } else if (un.c[0] == 0x02 && un.c[1] == 0x01) { printf("Little-Endian "); } else { printf("Unknown "); } getchar(); return 0; }