#include <iostream>
using namespace std;
/*
Little-endian :
数据的低位保存在内存的低地址中,而数据的高位保存在内存的高地址中
Big-endian :
数据的低位保存在内存的高地址中,而数据的高位保存在内存的低地址中
eg :
0x1122
Little-endian : 22 11
Big-endian : 11 22
*/
int main()
{
int x = 0x1122;
char x0, x1;
x0 = ((char*)&x)[0];
x1 = ((char*)&x)[1];
// VS2015使用的是Little-endian,输出结果x0=0x22,x1=0x11
printf("x0=0x%2x,x1=0x%2x\n", x0, x1);
system("pause");
return 0;
}
using namespace std;
/*
Little-endian :
数据的低位保存在内存的低地址中,而数据的高位保存在内存的高地址中
Big-endian :
数据的低位保存在内存的高地址中,而数据的高位保存在内存的低地址中
eg :
0x1122
Little-endian : 22 11
Big-endian : 11 22
*/
int main()
{
int x = 0x1122;
char x0, x1;
x0 = ((char*)&x)[0];
x1 = ((char*)&x)[1];
// VS2015使用的是Little-endian,输出结果x0=0x22,x1=0x11
printf("x0=0x%2x,x1=0x%2x\n", x0, x1);
system("pause");
return 0;
}