如何判断平台字节序的大小端?
作者:互联网
1.利用联合体所有成员起始位置一致
bool isLittleEndian()
{
union isLittle_Endian
{
int i;
char c;
};
isLittle_Endian check;
check.i = 1;
return check.c == 1;
}
O "是小端模式吗? " << isLittleEndian();
1.利用强制类型转换
bool isLittleEndian2()
{
int val = 0x12345678;
short *s = (short *)&val;
return s[1] == 0x1234;
}
O "是小端模式吗? " << isLittleEndian2();
标签:小端,判断,字节,val,int,平台,isLittle,bool,check 来源: https://blog.csdn.net/qq_43154850/article/details/122849089