int a = 0x11223344;
big-endian 平台上,字节存储顺序是:
存储格式:
底字节 --> 高字节
第一个字节 第二个字节 第三个字节 第四个字节
11 22 33 44
little-endian 平台上,字节存储顺序是:
存储格式:
底字节 --> 高字节
第一个字节 第二个字节 第三个字节 第四个字节
44 33 22 11
例子:
int main()
{
unsigned int a= 0x11223344;
char b ;
char c ;
char d,e ;
char * p ;
printf(" a = %x\n", a);
p = (unsigned char*)&a;
printf("p = %x\n", p);
b = *((unsigned char*)p);
p = p + 1;
printf("p+1 = %x\n", p);
c = *((unsigned char*)p);
p = p + 1;
printf("p+2 = %x\n", p);
d = *((unsigned char*)p);
p = p + 1;
printf("p+3 = %x\n", p);
e = *((unsigned char*)p);
printf("b = %x, c = %x, d = %x, e = %x \n", b, c, d, e);
}
结果 :
a = 11223344
p = bf9f64e4
p+1 = bf9f64e5
p+2 = bf9f64e6
p+3 = bf9f64e7
b = 44, c = 33, d = 22, e = 11