大小端

#include <stdio.h>
int main()
{
    union{
        short s;
        char c[sizeof(short)];
    }un;
    un.s = 0x0102;
    if (sizeof(short) == 2)
    {
        if (un.c[0] == 1 && un.c[1] == 2)
            printf("big-endian
");
        else if (un.c[0] == 2 && un.c[1] == 1)
            printf("little-endian
");
    }
    getchar();
    return 0;
}
原文地址:https://www.cnblogs.com/zzyoucan/p/11876733.html