编写一个函数,确定一台计算机采用大尾数法(big-endian)还是小尾数法(little-endian)。大小尾数问题指的是计算机存储多字节值时字节的顺序。
程序代码如下:
#include "stdafx.h"
#include <iostream.h>
方案1:
bool endianness()
{
int testNum;
char *ptr;
testNum = 1;
ptr = (char *)&testNum;
return (*ptr);
}
方案2:
bool endianness()
{
union
{
int theInteger;
char singleByte;
}endianTest;
endianTest.theInteger = 1;
return endianTest.singleByte;
}
int main()
{
bool a = endianness();
if(a)
cout << "大尾数" << endl;
else
cout << "小尾数" << endl;
return 0;
}
程序的执行结果如下:

最后
以上就是柔弱凉面最近收集整理的关于6. 大尾数法或小尾数法的全部内容,更多相关6.内容请搜索靠谱客的其他文章。
发表评论 取消回复