Skip to main content

Class BitReader

Reads individual bits sequentially from a byte array.

Declaration
public class BitReader

Fields

byteArray

Declaration
protected byte[] byteArray

byteIndex

Declaration
protected int byteIndex

byteBuffer

Declaration
protected byte byteBuffer

bitMask

Declaration
protected byte bitMask

Methods

ReadBit()

Reads a single bit as a boolean value where <i>true</i> represents 1 and <i>false</i> represents 0.

Declaration
public bool ReadBit()
Returns

System.Boolean

ReadBits(bool[], int, int)

Reads multiple bits as boolean values where <i>true</i> represents 1 and <i>false</i> represents 0.

Declaration
public void ReadBits(bool[] array, int offset, int length)
Parameters
TypeNameDescription
System.Boolean[]arrayAn array of boolean values into which the bits will be read.
System.Int32offsetAn offset (0-based) from which to begin storing the bits read.
System.Int32lengthThe maximum number of bits to be read.

ReadBits(bool[])

Reads multiple bits as boolean values where <i>true</i> represents 1 and <i>false</i> represents 0.

Declaration
public void ReadBits(bool[] array)
Parameters
TypeNameDescription
System.Boolean[]arrayAn array of boolean values into which the bits will be read.

ReadBits(int)

Reads multiple bits as boolean values where <i>true</i> represents 1 and <i>false</i> represents 0.

Declaration
public bool[] ReadBits(int length)
Returns

System.Boolean[]

Parameters
TypeNameDescription
System.Int32lengthThe maximum number of bits to be read.

ReadInt(int)

Reads a <i>base2</i> encoded signed integer.

Declaration
public int ReadInt(int length)
Returns

System.Int32

Parameters
TypeNameDescription
System.Int32lengthThe maximum number of bits to be read.

ReadLong(int)

Reads a <i>base2</i> encoded signed long integer.

Declaration
public long ReadLong(int length)
Returns

System.Int64

Parameters
TypeNameDescription
System.Int32lengthThe maximum number of bits to be read.

ReadFib()

Reads a Fibonacci encoded unsigned integer.

Declaration
public long ReadFib()
Returns

System.Int64

Reset()

Resets the bitMask and gets the next byte into the byteBuffer. The byteBuffer will be set to 0 if there are no more bytes to read.

Declaration
protected void Reset()