问题.文档说 ReadUint32 以小端读取所以第一个字节是最不重要的,所以它进入最低的内存位置.你的作者一定是大端的吗?This seems to be an endianness issue. The docs say ReadUint32 reads in little-endian so the first byte is the least-significant so it goes to the lowest memory location. Your writer must be big-endian?BinaryWriter.Write(UInt32) 说它写 也是小端.你的二进制数据源不是 BinaryWriter 吗?BinaryWriter.Write(UInt32) says it writes little-endian too. Is your binary data source not BinaryWriter?基本上你需要做的是修复它:Essentially what you need to do to fix it is this:uint a = 0x12345678;uint b = ((a & 0x000000FF) << 24) + ((a & 0x0000FF00) << 8) + ((a & 0x00FF0000) >> 8) + ((a & 0xFF000000) >> 24);这会将最低有效字节向上移动 24 位,将第二个 LSB 向上移动 8 位,将第三个 LSB 向下移动 8 位,将第四个 LSB(MSB)向下移动 24 位.这在几个库中都有介绍.This shifts the least-significant byte up 24 bits, the 2nd LSB up 8 bits, the 3rd LSB down 8 bits, and the 4th LSB (the MSB) down 24 bits. Doing this is covered in several libraries.也许使用 BitConverter 会更清楚一点:Perhaps using BitConverter would be a bit more clear:uint a = 0x12345678;byte[] bytes = BitConverter.GetBytes(a);// Swap byte orderuint b = BitConverter.ToUInt32(new byte[] { bytes[3], bytes[2], bytes[1], bytes[0] }, 0); 这篇关于为什么 BinaryReader.ReadUInt32() 反转位模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-16 16:11
查看更多