| PutBit |
|
|
|
|
long PutBit( BYTE BitBuffer, // buffer that contains data long NumberOfBits, // number of bits to write long FilePosition = -1 // position of data in file );
PutBit( BitBuffer As Variant, // variant that contains data NumberOfBits As Long, // number of bits to write FilePosition As Long = -1 // position of data in file ) As Long
Bits are buffered in special bit buffer which is one byte long and contains at most 8 bits to be written one by one. Bits are put into bit buffer from right to left - starting from least significant bit. If entire buffer is filled it is written to file as one complete byte and file positon is moved forward by one byte. Such behaviour guarantees that other non-bit data written by user is always accessed on byte boundary regardless of number of bits present in bit buffer. Read and written bits are never mixed in bit buffer; if GetBit call is followed by PutBit, bit buffer is discarded before bits are written; if PutBit call is followed by GetBit, bit buffer is written to file before bits are read. Bit buffer is flushed whenever other non-bit data is read, file is repositioned, resized, closed or detached.