Skip to content

Instantly share code, notes, and snippets.

@itczl22
Last active October 30, 2016 08:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itczl22/cf76465ed4596b0caae4977bfb6d1353 to your computer and use it in GitHub Desktop.
Save itczl22/cf76465ed4596b0caae4977bfb6d1353 to your computer and use it in GitHub Desktop.
大端小端存储
#include <stdio.h>
int main(void) {
// 储存方式的判断
unsigned int a = 0x12345678;
const char* buf = (char*)&a;
printf("%x\n%x\n", buf[0], buf[3]);
// 78 12, 所以是小端存储
const char* str = "12345678";
int* in = (int*)str;
printf("%x\n", in[1]);
return 0;
}
/*
1.in的地址和str的地址是相同的, in[1]指向'5678'
char :'5' '6' '7' '8'
hex :35 36 37 38
5是低字节,8是高字节
如果是小端储存就是: 0x38373635
如果是大端储存就是: 0x35363738
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment