Search code examples
cx86intelendiannessamd-processor

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


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 would be Intel-compatible.

Specifically, my processor is an AMD 64 Athlon x2.

I understand that this can matter in C programming. I'm writing C programs and a method I'm using would be affected by this. I'm trying to figure out if I'd get the same results if I ran the program on an Intel based machine (assuming that is little endian machine).

Finally, let me ask this: Would any and all machines capable of running Windows (XP, Vista, 2000, Server 2003, etc) and, say, Ubuntu Linux desktop be little endian?


Solution

  • 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 <stdio.h>
    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;
    }