BinaryWriter Endian issue

后端 未结 2 1444
北海茫月
北海茫月 2020-11-28 13:21

I am using BinaryWriter class to write a binary file to disk. When I invoke the Write method, passing an unsigned short value, it writes it in little-endian format. For exam

相关标签:
2条回答
  • 2020-11-28 13:28

    according to microsoft connect, it's currently not supported: http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=484149

    0 讨论(0)
  • 2020-11-28 13:48

    You can use my EndianBinaryWriter in MiscUtil. That lets you specify the endianness you want. There's also EndianBinaryReader and EndianBitConverter.

    EndianBinaryWriter writer = new EndianBinaryWriter(EndianBitConverter.Big,
                                                       stream);
    writer.Write(...);
    

    It doesn't derive from BinaryWriter, for reasons given in a blog post.

    0 讨论(0)
提交回复
热议问题