c# - BinaryReader 读取 4 个字节但未获得预期结果

标签 c# binary byte

我使用 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/

相关文章:

c# - C# 桌面应用程序中 Windows 窗体上的菜单

c# - 使用 Twitter 验证访问 token

binary - 用于二进制数加法和比较的图灵机

c# - 在 C# 中使用 Lambda 的一次性事件

c# - 在代码中引用 XAML 元素时出现 WPF NullReferenceException

c# - 使用 Entity Framework 6 从 SQL Server 保存和检索图像(二进制)

binary - Lua:将整数打印为二进制

c++ - 根据 vector<bool> 修改 char 的位

c# - 将 Byte[] 程序集加载到新的 AppDomain

android - h264 原始视频流格式