求助C# 读取高字节序二进制文件问题

小码要当程序猿 2012-12-02 12:30:29
我要读一个二进制文件,比如原二进制为
00 00 27 0A
我用
FileStream RFile = new FileStream(fileName, FileMode.Open, FileAccess.Read);

BinaryReader BRead = new BinaryReader(RFile);

int xxx=BRead.ReadInt32();

是按照低字节序读出来的xxx=170328064

170328064 为 0x0A270000

我想要的是0x0000270A,按照高字节序要怎么读呢?

...全文
317 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
引用 2 楼 sp1234 的回复:
C# code??123456public static Int32 ReadBigEndianInt32(this BinaryReader br){ var bt = br.ReadBytes(4); Array.Reverse(bt); return BitConverter.ToInt32(bt, 0);}
非常感谢,按照你说的我弄出了,谢谢了,网上牛人还是多
  • 打赏
  • 举报
回复
引用 2 楼 sp1234 的回复:
C# code??123456public static Int32 ReadBigEndianInt32(this BinaryReader br){ var bt = br.ReadBytes(4); Array.Reverse(bt); return BitConverter.ToInt32(bt, 0);}
好的,我试试
  • 打赏
  • 举报
回复
引用 1 楼 sp1234 的回复:
http://msdn.microsoft.com/zh-cn/library/vstudio/system.io.binaryreader.readint32.aspx
是啊,我看过了, BinaryReader 以 Little-Endian 格式读取此数据类型,但是我的二进制文件是以Big-Enbian格式存入的 我想要的是0x0000270A=9994要怎么弄呢
  • 打赏
  • 举报
回复
public static Int32 ReadBigEndianInt32(this BinaryReader br)
{
    var bt = br.ReadBytes(4);
    Array.Reverse(bt);
    return BitConverter.ToInt32(bt, 0);
}

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧