大端和小端存储

小端存储法——高地址存高字节,低地址存低字节(高存高,低存低)(intel/ARM)

0x表示十六进制

 

数值:0x12 34 56 78在小端存储器里如何存储

0x8003 0x12

0x8002 0x34

0x8001 0x56

0x8000  0x78

          

1 BYTE = 8bit

 

大端存储法——高地址存低字节,低地址存高字节(高存低,低存高)(IBM大型机/网络字节序)

数值:0x12 34 56 78在小端存储器里如何存储

 

0x8003 0x78

0x8002 0x56

0x8001 0x34

0x8000  0x12

 

可以判断是大端还是小端的程序。

//By jourluohua HEU

#include <iostream>

using namespace std;

int main(int argc, char *argv[])

{

unsigned char *p;

int x=0x12345678;

p=(unsigned char *)&x;

for(int i=0;i<4;i++)

{

cout<<hex<<(unsigned int )p<<"\t" <<(unsigned short)(*p)<<endl;

p++;

}

return 0;

}

 

原文地址:https://www.cnblogs.com/jourluohua/p/5456302.html