Skip to content

Instantly share code, notes, and snippets.

@itang
Created January 11, 2018 12:17
Show Gist options
  • Save itang/0da3ccb6d4be0dbff182151a3a14f22d to your computer and use it in GitHub Desktop.
Save itang/0da3ccb6d4be0dbff182151a3a14f22d to your computer and use it in GitHub Desktop.
typedef enum { false,
true } bool;
bool IsBigEndian()
{
int a = 0x1234;
char b = *(char *)&a; //通过将int强制类型转换成char单字节,通过判断起始存储位置。即等于 取b等于a的低地址部分
if (b == 0x12)
{
return true;
}
return false;
}
int main(int argc, char **argv)
{
printf("%d\n", IsBigEndian());
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment