我希望有人可以帮助我!
我想弄清楚如何完成以下操作。下面的十六进制存储为little-endian:
ff3f fc7f 0040 0000 ffff f17f 0000 0280
我试图了解作者如何将此转换(或重写)为:
7FFC 3FFF 0000 4000 7FF1 FFFF 8002 0000
我已经在互联网上搜索过但我不知所措:(
提前感谢所有有帮助的人!
答案 0 :(得分:1)
以下是不同数据类型的转换函数(您的情况是unsigned int):
//-----------------------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------------------
inline void endian_swap(unsigned short& x)
{
x = (x>>8) |
(x<<8);
}
//-----------------------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------------------
inline void endian_swap(unsigned int& x)
{
x = (x>>24) |
((x<<8) & 0x00FF0000) |
((x>>8) & 0x0000FF00) |
(x<<24);
}
//-----------------------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------------------
inline void endian_swap(unsigned __int64& x)
{
x = (x>>56) |
((x<<40) & 0x00FF000000000000) |
((x<<24) & 0x0000FF0000000000) |
((x<<8) & 0x000000FF00000000) |
((x>>8) & 0x00000000FF000000) |
((x>>24) & 0x0000000000FF0000) |
((x>>40) & 0x000000000000FF00) |
(x<<56);
}