Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write bits to a file?

Tags:

c#

.net

io

bit

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

like image 486
agnieszka Avatar asked Dec 17 '22 08:12

agnieszka


1 Answers

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

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

like image 94
driis Avatar answered Dec 26 '22 00:12

driis