Does my AMD-based machine use little endian or big endian?

前端 未结 7 1029
鱼传尺愫
鱼传尺愫 2020-12-05 02:54

I\'m going though a computers system course and I\'m trying to establish, for sure, if my AMD based computer is a little endian machine? I believe it is because it

7条回答
  •  广开言路
    2020-12-05 03:07

    All x86 and x86-64 machines (which is just an extension to x86) are little-endian.

    You can confirm it with something like this:

    #include 
    int main() {
        int a = 0x12345678;
        unsigned char *c = (unsigned char*)(&a);
        if (*c == 0x78) {
           printf("little-endian\n");
        } else {
           printf("big-endian\n");
        }
        return 0;
    }
    

提交回复
热议问题