我的基于 AMD 的机器使用小端还是大端? [英] Does my AMD-based machine use little endian or big endian?

查看:41
本文介绍了我的基于 AMD 的机器使用小端还是大端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习计算机系统课程,并且我正在尝试确定,肯定,如果我的基于 AMD 的计算机是小端机器?我相信这是因为它将与英特尔兼容.

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.

具体来说,我的处理器是 AMD 64 Athlon x2.

Specifically, my processor is an AMD 64 Athlon x2.

我知道这在 C 编程中很重要.我正在编写 C 程序,我正在使用的方法会受此影响.我想弄清楚如果我在基于 Intel 的机器上运行程序是否会得到相同的结果(假设小端机器).

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).

最后,让我问一下:任何和所有能够运行 Windows(XP、Vista、2000、Server 2003 等)的机器,比如 Ubuntu Linux 桌面是小端吗?

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?

推荐答案

所有 x86 和 x86-64 机器(只是 x86 的扩展)都是小端的.

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
");
    } else {
       printf("big-endian
");
    }
    return 0;
}

这篇关于我的基于 AMD 的机器使用小端还是大端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆