利用union判断CPU是大端模式还是小端模式
2024-03-26 07:47:42 阅读次数:20
CPU
#include <iostream>
using namespace std;
int checkCPU()
{
union w
{
int a;
char b;
} c;
c.a = 1;
return c.b == 1;//如果低地址还是1说明低地址存放低字节,小端
}//如果低地址不是1,则高地址是1,说明低地址存放高字节,大端
int main()
{
if (checkCPU())
{
cout << "The endian of cpu is little \n";
}
else
{
cout << "The endian of cpu is big \n";
}
return 0;
}
版权声明:本文内容来自第三方投稿或授权转载,原文地址:https://blog.51cto.com/u_14973569/6422261,作者:砖业洋__,版权归原作者所有。本网站转在其作品的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如因作品内容、版权等问题需要同本网站联系,请发邮件至ctyunbbs@chinatelecom.cn沟通。
上一篇:kvm迁移镜像启动报错(the CPU is incompatible with host CPU: Host CPU does not provide required features: fma)
下一篇:小朋友,你是否知道分离头指针呢?