测试程序
int check_sys()
{
union UN
{
char c;
int i;
}un;
un.i = 1;
if (un.c == 1)
return 0;//小端
else
return 1;//大端
}
int main()
{
int ret = check_sys();
if (ret == 0)
printf("little");
else
printf("big");
system("pause");
return 0;
}
转化程序
//int
int32_t swapInt32(int32_t value)
{
return ((value & 0x000000FF) << 24) |
((value & 0x0000FF00) << 8) |
((value & 0x00FF0000) >> 8) |
((value & 0xFF000000) >> 24) ;
}
//float
union intWithFloat
{
int32_t m_i32;
float m_f32;
}
float swapFloat32(float value)
{
intWithFloat i;
i.m_i32 = value;
i.m_f32 = swapInt32(i.m_i32)
return i.m_f32;
}
转自:https://blog.csdn.net/qq_16209077/article/details/80955844
转自:https://blog.csdn.net/zhuohaiyy/article/details/79105806