大端小端其实就是字节顺序。
以一个32位的整数为例0x12345678,该整数地址为0x400000000.
地址 | 大端 | 小端 |
---|---|---|
0x400000000 | 0x12 | 0x78 |
0x400000001 | 0x34 | 0x56 |
0x400000002 | 0x56 | 0x34 |
0x400000003 | 0x78 | 0x12 |
速记:
小小小 - 小端 小地址 存小数(低位的值)
/*****
> File Name: endian.c
> Author: Lin
> Mail: [email protected]
> Created Time: Tue Aug 6 15:36:27 2019
****/
#include <stdio.h>
int main()
{
union
{
int i;
char ch;
}endian_un;
endian_un.i = 1;
if(endian_un.ch == 1)
printf(“The Host is little endiann”);
else
printf(“The Host is big endiann”);
}
近期评论