Skip to main content

Class BitWriter

Writes individual bits sequentially using a System.IO.BinaryWriter.

Declaration
public class BitWriter : IDisposable

Implements:
System.IDisposable

Properties

Position

Gets the current position (in bits, starting at 0).

Declaration
public int Position { get; protected set; }

Fields

binaryWriter

Declaration
protected BinaryWriter binaryWriter

byteBuffer

Declaration
protected byte byteBuffer

bitMask

Declaration
protected byte bitMask

Methods

Write(bool)

Writes a boolean value where <i>true</i> is represented as 1 and <i>false</i> is represented as 0.

Declaration
public void Write(bool value)
Parameters
TypeNameDescription
System.BooleanvalueThe value to write.

Write(IEnumerable<bool>)

Writes a series of boolean values where <i>true</i> is represented as 1 and <i>false</i> is represented as 0.

Declaration
public void Write(IEnumerable<bool> values)
Parameters
TypeNameDescription
System.Collections.Generic.IEnumerable<System.Boolean>valuesAn enumerable collection of values to write.

Write(int, int)

Writes an unsigned integer using <i>base2</i> encoding.

Declaration
public void Write(int value, int length)
Parameters
TypeNameDescription
System.Int32valueThe value to write.
System.Int32lengthThe number of bits used to encode the value.

Write(uint, int)

Writes an unsigned integer using <i>base2</i> encoding.

Declaration
public void Write(uint value, int length)
Parameters
TypeNameDescription
System.UInt32valueThe value to write.
System.Int32lengthThe number of bits used to encode the value.

Write(long, int)

Writes an unsigned long integer using <i>base2</i> encoding.

Declaration
public void Write(long value, int length)
Parameters
TypeNameDescription
System.Int64valueThe value to write.
System.Int32lengthThe number of bits used to encode the value.

Write(ulong, int)

Writes an unsigned long integer using <i>base2</i> encoding.

Declaration
public void Write(ulong value, int length)
Parameters
TypeNameDescription
System.UInt64valueThe value to write.
System.Int32lengthThe number of bits used to encode the value.

WriteFib(int)

Writes an unsigned integer in Fibonacci encoding.

Declaration
public void WriteFib(int value)
Parameters
TypeNameDescription
System.Int32valueThe value to write.

Flush()

Flushes whatever is in the buffer to the underlying binary writer.

Declaration
public void Flush()

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Declaration
public void Dispose()

Reset()

Resets the bitMask and clears the byteBuffer.

Declaration
protected void Reset()

AdvancePosition()

Moves the position to the next bit; flushing and reseting if needed.

Declaration
protected void AdvancePosition()

ComputeFib(uint)

Declaration
protected static uint ComputeFib(uint value)
Returns

System.UInt32

Parameters
TypeName
System.UInt32value

Implements

  • System.IDisposable