big endian & little endian(大端字节序和小端字节序)
假设:a=0x12345678;
则大端字节序和小端字节序的存储如下图所示:
Big-Endian Little-Endian
0字节 12h 78h
1字节 34h 56h
2字节 56h 34h
3字节 78h 21h
你也可以用下面的程序测验你的机器是大端字节序还是小端字节序:
#include <stdio.h>
int IsLittleEndian() { unsigned int usData = 0x12345678; unsigned char *pucData = (unsigned char*)&usData;
if(*pucData == 0x78) { return 1; } else { return 0; }
}
int main(void) { if(IsLittleEndian()) { printf("is little endian!\n"); } else { printf("is big endian!\n"); }
return 0; }
|
阅读(1223) | 评论(0) | 转发(0) |