如何将位写入文件? [英] How to write bits to a file?

查看:140
本文介绍了如何将位写入文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何用c#,. net将文件(而不是字节)写入文件?我很乐意坚持下去。

编辑:我正在寻找一种不同的方式,只需将每8位写入一个字节

How to write bits (not bytes) to a file with c#, .net? I'm preety stuck with it.
Edit: i'm looking for a different way that just writing every 8 bits as a byte

推荐答案

一次可以写入的最小数据量是一个字节。

The smallest amount of data you can write at one time is a byte.

如果需要写单个位值。 (例如,需要1位标志,3位整数和4位整数的二进制格式);你需要缓冲内存中的各个值,并在有一个完整的字节写入时写入文件。 (为了提高性能,缓冲更多并将更大的块写入文件是有意义的。)

If you need to write individual bit-values. (Like for instance a binary format that requires a 1 bit flag, a 3 bit integer and a 4 bit integer); you would need to buffer the individual values in memory and write to the file when you have a whole byte to write. (For performance, it makes sense to buffer more and write larger chunks to the file).

这篇关于如何将位写入文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆