使用共用体实现大小端存储
#include <myhead.h>
typedef union
{
int num;
char p;
}Test;
int main(int argc, const char *argv[])
{
Test a;
a.num=0x12345678;
if(a.p==0x12)
{
printf("大端存储\n");
}
if(a.p==0x78)
{
printf("小端存储\n");
}
return 0;
}
结果:
思维导图:https://mubu.com/app/edit/home/3jLk1ZhmzUD#m