我使用 BinaryReader 读取文件,但遇到无法解决的问题。 (c#)
我需要读取 4 个字节。当我用我的十六进制查看器查看这些字节时,它是 00 00 00 13
。
所以我尝试了 Int32 fLength = dbr.ReadInt32();
结果是 318767104 而不是 19(我期望和需要的)。当我使用 byte[] fLength = dbr.ReadBytes(4);
时,我可以看到我读取了正确的字节 [0] [0] [0] [19]。
(我对以下字节有同样的问题)
我怎样才能读取这 4 个字节并得到 19 作为结果。
提前致谢!
罗伯蒂科
最佳答案
这是一个little endian vs big endian问题:318767104 = 0x13000000
来自documentation :
BinaryReader stores this data type in little endian format.
乔恩·斯基特的 miscutil有一个阅读器可以让你选择大端或小端。
关于c# - BinaryReader 读取 4 个字节但未获得预期结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7695173/