Class BitReader
Reads individual bits sequentially from a byte array.
public class BitReader
Fields
byteArray
protected byte[] byteArray
byteIndex
protected int byteIndex
byteBuffer
protected byte byteBuffer
bitMask
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
.
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
.
public void ReadBits(bool[] array, int offset, int length)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean[] | array | An array of boolean values into which the bits will be read. |
System.Int32 | offset | An offset (0-based) from which to begin storing the bits read. |
System.Int32 | length | The 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
.
public void ReadBits(bool[] array)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean[] | array | An 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
.
public bool[] ReadBits(int length)
Returns
System.Boolean[]
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | length | The maximum number of bits to be read. |
ReadInt(int)
Reads a <i>base2</i> encoded signed integer.
public int ReadInt(int length)
Returns
System.Int32
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | length | The maximum number of bits to be read. |
ReadLong(int)
Reads a <i>base2</i> encoded signed long integer.
public long ReadLong(int length)
Returns
System.Int64
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | length | The maximum number of bits to be read. |
ReadFib()
Reads a Fibonacci encoded unsigned integer.
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.
protected void Reset()