测试机器大小端字节序的小程序
来源:互联网 发布:华电电科院 知乎 编辑:程序博客网 时间:2024/04/27 14:22
现代机器的字节序组织有两种方式,即大端序组织(big endian)和小端序组织(little endian),典型的Intel 80x86 CPU使用的是little endian,而苹果Macintosh和大多数非80x86的系统使用的是big endian。
这两个名字来源于Jonathan Swift 的作品《格列佛游记》(Gulliver's Travels),小人国的居民们争吵不决鸡蛋是应该从大的一端打开还是应该从小的一端打开,后来计算机的字节序组织也沿用了这种叫法。。。
关于little endian的解释:"Little Endian" means that the low-order byte of the number is stored in memory at the lowest address, and the high-order byte at the highest address.
关于big endian的解释:"Big Endian" means that the high-order byte of the number is stored in memory at the lowest address, and the low-order byte at the highest address.
下面是一段测试机器大小端字节序的代码
#include<stdio.h>
union...{
unsigned long bits32;
unsigned char bytes[4];
}value;
int isLittleEndian()...{
value.bytes[0] = 0;
value.bytes[1] = 1;
value.bytes[2] = 0;
value.bytes[3] = 0;
return value.bits32 == 256;
}
int main()...{
if( isLittleEndian())
printf("is little endian! ");
else
printf("is big endian! ");
return 0;
}
union...{
unsigned long bits32;
unsigned char bytes[4];
}value;
int isLittleEndian()...{
value.bytes[0] = 0;
value.bytes[1] = 1;
value.bytes[2] = 0;
value.bytes[3] = 0;
return value.bits32 == 256;
}
int main()...{
if( isLittleEndian())
printf("is little endian! ");
else
printf("is big endian! ");
return 0;
}
- 测试机器大小端字节序的小程序
- C语言测试机器大小端字节序
- 什么是大端字节序?什么是小端字节序?如何用共用体判断机器的大小端?
- 如何简单的判断机器的大小端字节序
- 用C++程序检查机器的字节序(大端或小端)
- 题目:编写一个程序,测试运行它的平台是大端字节序还是小端字节序。
- 面试题目---小字节序、大字节序、程序判断 网络字节 主流机器字节序
- 一个测试栈大小的小程序
- 机器字节序测试
- 判断机器大小字节序
- 测试大小端的程序&测试数据类型占用的字节数
- 测试机器大小端
- 一个判断机器字节序(big endian/little endian)的小程序
- 测试机器大小端的方法
- 测试机器大小端存储的方法
- 大端和小端机器中字节序问题延伸: 在字节内部位序是怎么样的?
- 规避Mac下机器的大小字节序问题
- C语言小程序判断机器大小端存储
- asp.net导出excel
- 套接口和标准IO
- 得到动态sql信息
- linux系统优化设置及软件集合
- 数据结构(C#)_排序算法(插入排序)
- 测试机器大小端字节序的小程序
- oracle 中关于左连接
- 10种方法让你管理网站更有效率
- 系统分析师之路
- 失败的面试
- 关于调用Spring设置Quartz中动态执行时间解决办法
- RMI应用中常遇到的一些问题
- IE6的一個小bug
- 获取机器的硬件信息(CPU ID序列号, 主板信息,硬盘序列号,系统信息)