判断字节序

来源:互联网 发布:广西电子政务云计算 编辑:程序博客网 时间:2024/06/03 18:12
#include <stdio.h>

typedef union
{
    unsigned short int value;
    unsigned char byte[2];
}to;

int main(int argc, char *argv)
{
    to typeorder;
    typeorder.value = 0x1234;

    if (typeorder.byte[0] == 0x12&& typeorder.byte[1] == 0x34)
    {
        printf("Big endian byte order!\n");
    }
    if (typeorder.byte[0] == 0x34&& typeorder.byte[1] == 0x12)
    {
     printf("Little endian byte order!\n");
    }
    return 0;
}

原创粉丝点击