- 一个十六位整数,由两个字节组成。内存中存储这两个字节有两种方法:
- 一种是将低序字节存储在起始位置,这称为小端序(little-endian)
- 另一种方法是将高字节存储在起始位置,这称为大端序(big-endian)
测试本机是哪一种模式
- 实验代码
/*
*该程序最低运行环境为32位系统。
*/
#include <stdio.h>
int main(void)
{
unsigned int num = 0x12345678;
for(int i = 0; i < 4; i++)
printf("%0x\n",*((char *)(&num) + i));
return 0;
}
- 如果结果显示为下面所示,则为小端模式。
78 |
56 |
34 |
12 |
- 如果结果显示为下面所示,则为小端模式。
12 |
34 |
56 |
78 |