请简述字节序的概念(概念、大小端),用共用体的方式求本机的大小端。
字节序:就是根据不同的CPU架构,内存储存多字节整数序列的方式。
#include <stdio.h>
typedef union{
int a;
char b;
}t;
void main()
{
t un;
un.a=0x12345678;
if(un.b==0x78)
{
printf("小端\n");
}
else
{
printf("大端\n");
}
}
请简述字节序的概念(概念、大小端),用共用体的方式求本机的大小端。
字节序:就是根据不同的CPU架构,内存储存多字节整数序列的方式。
#include <stdio.h>
typedef union{
int a;
char b;
}t;
void main()
{
t un;
un.a=0x12345678;
if(un.b==0x78)
{
printf("小端\n");
}
else
{
printf("大端\n");
}
}