How to check whether a system is big endian or little endian?

后端 未结 12 929
时光说笑
时光说笑 2020-11-28 20:25

How to check whether a system is big endian or little endian?

12条回答
  •  旧时难觅i
    2020-11-28 21:28

    Another C code using union

    union {
        int i;
        char c[sizeof(int)];
    } x;
    x.i = 1;
    if(x.c[0] == 1)
        printf("little-endian\n");
    else    printf("big-endian\n");
    

    It is same logic that belwood used.

提交回复
热议问题