【发布时间】:2012-04-22 23:16:11
【问题描述】:
我正在使用 System.IO.BinaryReader 从序列化文件中读取数据。该文件是大端。所以我从流中读取 Int64 (long) 的操作是从中读取 8 个字节。我需要做的就是将这 8 个字节的 big endian 转换为 little endian long 表示。
我不能使用 System.BitConverter,因为它将使用 Mono 编译以在 Linux 上使用,可以在大端和 Visual Studio for Windows 上运行,它可以在小端上运行。
【问题讨论】:
-
那是什么? Mono 也实现了
System.BitConverter——当然。 -
我读到 here 说“BitConverter.ToInt64 应该尊重你的底层机器的字节顺序。”
-
长值 = Convert.ToInt64(binaryReader.ReadBytes(8).Reverse()); Skeet 使用 big-endian 做了一些事情,请查看他的博客。
-
Convert.ToInt* 不采用字节数组
标签: c# .net mono bitconverter