作业
判断计算机是字节序是大端还是小端
//判断计算机是字节序是大端还是小端
#include <stdio.h>
union Data{
unsigned int a;
char b;
} data;
int main(int argc, const char *argv[])
{
//0x12是高位字节,0x78是低位字节
data.a = 0x12345678;
if(0x12 == data.b){
//大端字节序:高地址字节存储在低地址上
printf("高端字节序\n");
}else if(0x78 == data.b){
//小端字节序:低地址字节存储在低地址上
printf("小端字节序\n");
}
return 0;
}
ubuntu@ubuntu:20230309_net$ gcc 01_byte_order.c
ubuntu@ubuntu:20230309_net$ ./a.out
小端字节序