的BinaryWriter尾段问题

编程入门 行业动态 更新时间:2024-10-27 08:31:31
本文介绍了的BinaryWriter尾段问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用的BinaryWriter类写一个二进制文件保存到磁盘。当我调用Write方法,传递一个无符号短值,它写入在小端格式。例如:

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 example:

bw.Write(0xA000);

写入值的二进制文件为0x00 0XA0。有没有一种方法,使的BinaryWriter使用大端?如果不是,是有可能创造一个新的类,继承的BinaryWriter和过载的写入功能,使其写大端?

writes the value in the binary file as 0x00 0xA0. Is there a way to make BInaryWriter use Big Endian? If not, is it possible to create a new class, inheriting BinaryWriter and overload the Write function to make it write big endian?

推荐答案

您可以用我的 EndianBinaryWriter 中的 MiscUtil 。这使您可以指定所需的字节顺序。还有 EndianBinaryReader 和 EndianBitConverter 。

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(...);

它不会从的BinaryWriter 导出,其原因的在博客中给出。

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

更多推荐

的BinaryWriter尾段问题

本文发布于:2023-11-09 10:37:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1572158.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:尾段   BinaryWriter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!