09-18-2015 01:43 PM
Is there a way to remove few bits from start of binary file. All file functions are byte based, not bit based. My files are large (GB size) so I would prefer not to read/write files as characters as this takes a long time.
09-18-2015 04:08 PM
I don't know what you mean by removing a few bits from the beginning of a file.
Files only store data in the units of bytes. It can't read or write individual bits.
09-18-2015 04:09 PM
What do you really want to do? Suppose I have a file that is four bytes (32 bits) in length, and you want to remove 3 bits. What happens? Do all of the bits "slide down" by three? Or is only the first byte affected?
If your file really is a bit-stream and you want to remove "a few" bits, you are pretty much going to have to read and rewrite every single byte. However, if you read the file as a U64, or 8 bytes at a time, you can "slide down" your bits on the U64, potentially cutting down the number of separate I/O calls by a factor of 8. You'll, of course, need to fill in the "missing bits" from the next-higher chunk, and will also need to worry about handling the final few "odd" bytes in the file ...
Glad I don't have to do this -- sounds messy.
Bob Schor
09-18-2015 05:37 PM
Bob_Schor wrote:
Glad I don't have to do this -- sounds messy.
It is. I once had to interface with a UUT that used a 12-bit PCM stream. Why 12-bit? Saves bandwidth over 16-bit. Enough to really matter in real situations? No. Complicated as $*^&? YES! Worth doing? Not in my opinion.