ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

delete bits from binary file

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.

0 Kudos
Message 1 of 4
(4,539 Views)

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.

0 Kudos
Message 2 of 4
(4,515 Views)

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

Message 3 of 4
(4,513 Views)

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.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 4
(4,498 Views)