大小端這個問題在面試過程中偶爾會被問到,這裏筆者總結了一
int CheckSystemDataFormat(void)
{
int i = 0x0a12780b;
char *c = &i;
return ((c[0] == 0x0a) && (c[1] == 0x12) && (c[2] == 0x78) && (c[3] == 0x0b));
}
int main(void)
{
if(CheckSystemDataFormat())
printf("little endian\n");
else
printf("big endian\n");
return 0;
}