请简述字节序的概念,并用联合体(共用体)的方式验证计算机是大端还是小端?
字节序是计算机存储 多字节整数 序列的方式
#include<stdio.h>
union
{
unsigned int a;
char b[4];
}byte;
int main(int argc, const char *argv[])
{
byte.a = 0x87654321;
if(0x21 == byte.b[0])
{
printf("小端字节序\n");
}
else if(0x87 == byte.b[0])
{
printf("大端字节序\n");
}
return 0;
}
结果: