struct TestPoint3d
{
union
{
struct
{
unsigned int x:1;
unsigned int y:1;
unsigned int z:30;
};
unsigned int loc;
};
};
int main()
{
test.loc = 6;
/*
*如果返回true 那么表示小端,否则为大端
*/
bool isLittleEnd = (x ? false : true);
}
本文介绍了一种使用位字段(struct)和联合(union)来实现内存紧凑存储的方法,并通过一个简单的例子展示了如何判断计算机系统的字节序(小端或大端)。此方法对于嵌入式系统和网络编程中数据的高效存储与传输具有重要意义。
struct TestPoint3d
{
union
{
struct
{
unsigned int x:1;
unsigned int y:1;
unsigned int z:30;
};
unsigned int loc;
};
};
int main()
{
test.loc = 6;
/*
*如果返回true 那么表示小端,否则为大端
*/
bool isLittleEnd = (x ? false : true);
}
2725

被折叠的 条评论
为什么被折叠?