Struct BitVectorSpan
Represents a slice of an array of bits for which the concrete may be known or unknown, and can be reinterpreted as different value types, and operated on using the different semantics of these types.
public readonly ref struct BitVectorSpan
- Inherited Members
Constructors
BitVectorSpan(BitVector)
Creates a new span around an existing bitvector.
public BitVectorSpan(BitVector vector)
Parameters
vectorBitVectorThe vector to span.
BitVectorSpan(Span<byte>, Span<byte>)
Creates a new span around a pair of bits and a known bit mask.
public BitVectorSpan(Span<byte> bits, Span<byte> knownMask)
Parameters
bitsSpan<byte>The concrete bits stored in the bit vector.
knownMaskSpan<byte>The bitmask indicating which bits in
bitsare known.
Exceptions
- ArgumentException
Occurs when the length of
bitsandknownMaskdo not match up.
Properties
Bits
Gets the raw bits stored in this bit vector span.
public Span<byte> Bits { get; }
Property Value
ByteCount
Gets the number of bytes stored in the bit vector.
public int ByteCount { get; }
Property Value
Count
Gets the number of bits stored in the bit vector.
public int Count { get; }
Property Value
F32
Interprets the bit vector as a 32 bit floating point number, and gets or sets the immediate value for it.
public float F32 { get; set; }
Property Value
F64
Interprets the bit vector as a 64 bit floating point number, and gets or sets the immediate value for it.
public double F64 { get; set; }
Property Value
I16
Interprets the bit vector as a signed 16 bit integer, and gets or sets the immediate value for it.
public short I16 { get; set; }
Property Value
I32
Interprets the bit vector as a signed 32 bit integer, and gets or sets the immediate value for it.
public int I32 { get; set; }
Property Value
I64
Interprets the bit vector as a signed 64 bit integer, and gets or sets the immediate value for it.
public long I64 { get; set; }
Property Value
I8
Interprets the bit vector as a signed 8 bit integer, and gets or sets the immediate value for it.
public sbyte I8 { get; set; }
Property Value
IsFullyKnown
Gets a value indicating whether all bits in the vector are known.
public bool IsFullyKnown { get; }
Property Value
IsZero
Gets a value indicating whether all bits in the vector are set to zero.
public Trilean IsZero { get; }
Property Value
this[int]
Gets or sets a single bit in the bit vector span.
public Trilean this[int index] { get; set; }
Parameters
indexintThe index of the bit to get.
Property Value
KnownMask
Gets a bit mask indicating which bits in Bits are known.
public Span<byte> KnownMask { get; }
Property Value
U16
Interprets the bit vector as an unsigned 16 bit integer, and gets or sets the immediate value for it.
public ushort U16 { get; set; }
Property Value
U32
Interprets the bit vector as an unsigned 32 bit integer, and gets or sets the immediate value for it.
public uint U32 { get; set; }
Property Value
U64
Interprets the bit vector as an unsigned 64 bit integer, and gets or sets the immediate value for it.
public ulong U64 { get; set; }
Property Value
U8
Interprets the bit vector as an unsigned 8 bit integer, and gets or sets the immediate value for it.
public byte U8 { get; set; }
Property Value
Methods
And(BitVectorSpan)
Performs a bitwise AND operation with another bit vector.
public void And(BitVectorSpan other)
Parameters
otherBitVectorSpanThe other bit vector.
Clear()
Clears the bit vector with zeroes.
public void Clear()
CopyTo(BitVectorSpan)
Copies all bits and known bit mask to the provided bit vector.
public void CopyTo(BitVectorSpan buffer)
Parameters
bufferBitVectorSpanThe bit buffer to copy the bits to.
Equals(BitVectorSpan)
Compares two BitVectorSpan's
public bool Equals(BitVectorSpan other)
Parameters
otherBitVectorSpanThe BitVectorSpan to compare to
Returns
- bool
Whether the two BitVectorSpan's are equal
Remarks
This overload exists to avoid boxing allocations.
Equals(object?)
public override bool Equals(object? obj)
Parameters
objobject
Returns
Fill(byte)
Fills the bit vector with the repetition of a byte.
public void Fill(byte value)
Parameters
valuebyteThe value to fill the bit vector with.
Fill(byte, byte)
Fills the bit vector with the repetition of a partially known byte.
public void Fill(byte value, byte knownMask)
Parameters
valuebyteThe value to fill the bit vector with.
knownMaskbyteThe mask indicating which bits in
valueare known.
FloatAdd(BitVectorSpan)
Interprets the bitvector as a floating point number, and adds another floating point number to it.
public void FloatAdd(BitVectorSpan other)
Parameters
otherBitVectorSpan
FloatDivide(BitVectorSpan)
Interprets the bitvector as a floating point number, and divides it with another floating point number.
public void FloatDivide(BitVectorSpan other)
Parameters
otherBitVectorSpan
FloatIsGreaterThan(BitVectorSpan, bool)
interprets the bitvector as a floating point number, and determines whether it is greater than the provided floating point bitvector.
public Trilean FloatIsGreaterThan(BitVectorSpan other, bool ordered)
Parameters
otherBitVectorSpanThe other floating point number.
orderedboolA value indicating whether the comparison should be an ordered comparison or not.
Returns
- Trilean
True if the current number is greater than the provided number, False if not, and Unknown if the conclusion of the comparison is not certain.
FloatIsLessThan(BitVectorSpan, bool)
interprets the bitvector as a floating point number, and determines whether it is smaller than the provided floating point bitvector.
public Trilean FloatIsLessThan(BitVectorSpan other, bool ordered)
Parameters
otherBitVectorSpanThe other floating point number.
orderedboolA value indicating whether the comparison should be an ordered comparison or not.
Returns
- Trilean
True if the current number is less than the provided number, False if not, and Unknown if the conclusion of the comparison is not certain.
FloatMultiply(BitVectorSpan)
Interprets the bitvector as a floating point number, and multiplies it with another floating point number.
public void FloatMultiply(BitVectorSpan other)
Parameters
otherBitVectorSpan
FloatNegate()
Interprets the bitvector as a floating point number, and negates it.
public void FloatNegate()
FloatRemainder(BitVectorSpan)
Interprets the bitvector as a floating point number, divides it with another floating point number and stores the remainder of the division.
public void FloatRemainder(BitVectorSpan other)
Parameters
otherBitVectorSpan
FloatSubtract(BitVectorSpan)
Interprets the bitvector as a floating point number, and subtracts another floating point number to it.
public void FloatSubtract(BitVectorSpan other)
Parameters
otherBitVectorSpan
GetHashCode()
public override int GetHashCode()
Returns
GetMsb()
Interprets the bit vector as an integer, and obtains the most significant bit (MSB) of the bit vector.
public Trilean GetMsb()
Returns
IntegerAdd(BitVectorSpan)
Interprets the bit vector as an integer and adds a second integer to it.
public Trilean IntegerAdd(BitVectorSpan other)
Parameters
otherBitVectorSpanThe integer to add.
Returns
- Trilean
The value of the carry bit after the addition completed.
Exceptions
- ArgumentException
Occurs when the sizes of the integers do not match in bit length.
IntegerDecrement()
Interprets the bit vector as an integer and decrements it by one.
public Trilean IntegerDecrement()
Returns
- Trilean
The value of the carry bit after the decrement operation completed.
IntegerDivide(BitVectorSpan)
Interprets the bit vector as an integer and divides it by a second integer.
public void IntegerDivide(BitVectorSpan other)
Parameters
otherBitVectorSpanThe integer to divide the current integer by.
Exceptions
- ArgumentException
Occurs when the sizes of the integers do not match in bit length.
IntegerIncrement()
Interprets the bit vector as an integer and increments it by one.
public Trilean IntegerIncrement()
Returns
- Trilean
The value of the carry bit after the increment operation completed.
IntegerIsGreaterThan(BitVectorSpan, bool)
Interprets the bit vector as an integer, and determines whether the integer is greater than another integer.
public Trilean IntegerIsGreaterThan(BitVectorSpan other, bool signed)
Parameters
otherBitVectorSpanThe other integer.
signedboolIndicates the integers should be interpreted as signed or unsigned integers.
Returns
- Trilean
True if the current integer is greater than the provided integer, False if not, and Unknown if the conclusion of the comparison is not certain.
IntegerIsGreaterThanOrEqual(BitVectorSpan, bool)
Interprets the bit vector as an integer, and determines whether the integer is greater than or equal to another integer.
public Trilean IntegerIsGreaterThanOrEqual(BitVectorSpan other, bool signed)
Parameters
otherBitVectorSpanThe other integer.
signedboolIndicates the integers should be interpreted as signed or unsigned integers.
Returns
- Trilean
True if the current integer is greater than or equal to the provided integer, False if not, and Unknown if the conclusion of the comparison is not certain.
IntegerIsLessThan(BitVectorSpan, bool)
Interprets the bit vector as an integer, and determines whether the integer is less than another integer.
public Trilean IntegerIsLessThan(BitVectorSpan other, bool signed)
Parameters
otherBitVectorSpanThe other integer.
signedboolIndicates the integers should be interpreted as signed or unsigned integers.
Returns
- Trilean
True if the current integer is less than the provided integer, False if not, and Unknown if the conclusion of the comparison is not certain.
IntegerIsLessThanOrEqual(BitVectorSpan, bool)
Interprets the bit vector as an integer, and determines whether the integer is less than or equal to another integer.
public Trilean IntegerIsLessThanOrEqual(BitVectorSpan other, bool signed)
Parameters
otherBitVectorSpanThe other integer.
signedboolIndicates the integers should be interpreted as signed or unsigned integers.
Returns
- Trilean
True if the current integer is greater than or equal to the provided integer, False if not, and Unknown if the conclusion of the comparison is not certain.
IntegerMultiply(BitVectorSpan)
Interprets the bit vector as an integer and multiplies it by a second integer.
public Trilean IntegerMultiply(BitVectorSpan other)
Parameters
otherBitVectorSpanThe integer to multiply the current integer with.
Returns
- Trilean
A value indicating whether the result was truncated.
Exceptions
- ArgumentException
Occurs when the sizes of the integers do not match in bit length.
IntegerNegate()
Interprets the bit vector as an integer and negates it according to the two's complement semantics.
public void IntegerNegate()
IntegerRemainder(BitVectorSpan)
Interprets the bit vector as an integer, divides it by a second integer and produces the remainder.
public void IntegerRemainder(BitVectorSpan other)
Parameters
otherBitVectorSpanThe integer to divide the current integer by.
Exceptions
- ArgumentException
Occurs when the sizes of the integers do not match in bit length.
IntegerSubtract(BitVectorSpan)
Interprets the bit vector as an integer and subtracts a second integer from it.
public Trilean IntegerSubtract(BitVectorSpan other)
Parameters
otherBitVectorSpanThe integer to subtract.
Returns
- Trilean
The value of the borrow bit after the subtraction completed.
Exceptions
- ArgumentException
Occurs when the sizes of the integers do not match in bit length.
IsEqualTo(BitVectorSpan)
Determines whether the current bit vector is equal to another bit vector.
public Trilean IsEqualTo(BitVectorSpan other)
Parameters
otherBitVectorSpanThe other bit vector.
Returns
- Trilean
True if the bit vector are equal, False if not, and Unknown if the conclusion of the comparison is not certain.
MarkFullyKnown()
Marks the entire bit vector fully known, treating all bits in Bits as actual data.
public void MarkFullyKnown()
Remarks
This is effectively setting all bits in KnownMask.
MarkFullyUnknown()
Marks the entire bit vector fully unknown.
public void MarkFullyUnknown()
Remarks
Not()
Inverts all the bits in the vector.
public void Not()
Or(BitVectorSpan)
Performs a bitwise OR operation with another bit vector.
public void Or(BitVectorSpan other)
Parameters
otherBitVectorSpanThe other bit vector.
ReadNativeInteger(bool)
Reads a native integer from the vector.
public long ReadNativeInteger(bool is32Bit)
Parameters
is32BitboolA value indicating whether the native integer is 32 or 64 bits wide.
Returns
- long
The read integer.
ShiftLeft(int)
Shift all bits in the vector to the left, filling the least significant bits with zeroes.
public void ShiftLeft(int count)
Parameters
countintThe number of bits to shift with.
ShiftRight(int, bool)
Shift all bits in the vector to the right, and either sign- or zero-extends the value.
public void ShiftRight(int count, bool signExtend)
Parameters
countintThe number of bits to shift with.
signExtendboolGets a value indicating whether the bits should be sign- or zero-extended.
Slice(int)
Forms a slice of a bit vector that starts at a provided bit index.
public BitVectorSpan Slice(int bitIndex)
Parameters
bitIndexintThe bit index to start the slice at.
Returns
- BitVectorSpan
The constructed slice.
Exceptions
- ArgumentOutOfRangeException
Occurs when the bit index is not a multiple of 8.
Slice(int, int)
Forms a slice of a bit vector that starts at a provided bit index and has a provided length.
public BitVectorSpan Slice(int bitIndex, int length)
Parameters
Returns
- BitVectorSpan
The constructed slice.
Exceptions
- ArgumentOutOfRangeException
Occurs when the bit index is not a multiple of 8.
ToBitString()
Constructs a binary string that represents the binary number stored in the bit vector.
public string ToBitString()
Returns
- string
The binary string.
Remarks
When a bit is marked as unknown, its digit is replaced with a question mark (?).
ToHexString()
Constructs a string that represents the raw data stored in the bit vector as a hexadecimal byte string.
public string ToHexString()
Returns
- string
The byte string.
Remarks
When any bit in a nibble is marked as unknown, its digit is replaced with a question mark (?).
ToVector()
Copies the span into a new bit vector.
public BitVector ToVector()
Returns
- BitVector
The vector.
ToVector(BitVectorPool)
Copies the span into a new bit vector that is rented from the provided pool.
public BitVector ToVector(BitVectorPool pool)
Parameters
poolBitVectorPoolThe pool to rent the vector from.
Returns
- BitVector
The vector.
Write(BitVectorSpan)
Writes data into the bit vector.
public void Write(BitVectorSpan data)
Parameters
dataBitVectorSpanThe data to write.
Write(byte)
Interprets the bit vector as an unsigned 8 bit integer, and writes a fully known immediate value to it.
public void Write(byte value)
Parameters
valuebyteThe value.
Write(byte, byte)
Interprets the bit vector as an unsigned 8 bit integer, and writes a partially known immediate value to it.
public void Write(byte value, byte knownMask)
Parameters
Write(double)
Interprets the bit vector as a 64 bit floating point number, and writes a fully known immediate value to it.
public void Write(double value)
Parameters
valuedoubleThe value.
Write(short)
Interprets the bit vector as a signed 16 bit integer, and writes a fully known immediate value to it.
public void Write(short value)
Parameters
valueshortThe value.
Write(short, ushort)
Interprets the bit vector as a signed 16 bit integer, and writes a partially known immediate value to it.
public void Write(short value, ushort knownMask)
Parameters
Write(int)
Interprets the bit vector as a signed 32 bit integer, and writes a fully known immediate value to it.
public void Write(int value)
Parameters
valueintThe value.
Write(int, uint)
Interprets the bit vector as a signed 32 bit integer, and writes a partially known immediate value to it.
public void Write(int value, uint knownMask)
Parameters
Write(long)
Interprets the bit vector as a signed 64 bit integer, and writes a fully known immediate value to it.
public void Write(long value)
Parameters
valuelongThe value.
Write(long, ulong)
Interprets the bit vector as an signed 64 bit integer, and writes a partially known immediate value to it.
public void Write(long value, ulong knownMask)
Parameters
Write(ReadOnlySpan<byte>)
Writes fully known bytes into the bit vector.
public void Write(ReadOnlySpan<byte> data)
Parameters
dataReadOnlySpan<byte>The data to write.
Write(ReadOnlySpan<byte>, ReadOnlySpan<byte>)
Writes data into the bit vector.
public void Write(ReadOnlySpan<byte> data, ReadOnlySpan<byte> knownMask)
Parameters
dataReadOnlySpan<byte>The data to write.
knownMaskReadOnlySpan<byte>The mask indicating which bits in
dataare known.
Exceptions
- ArgumentOutOfRangeException
Occurs when the length of
dataandknownMaskdo not match.
Write(sbyte)
Interprets the bit vector as a signed 8 bit integer, and writes a fully known immediate value to it.
public void Write(sbyte value)
Parameters
valuesbyteThe value.
Write(sbyte, byte)
Interprets the bit vector as a signed 8 bit integer, and writes a partially known immediate value to it.
public void Write(sbyte value, byte knownMask)
Parameters
Write(float)
Interprets the bit vector as a 32 bit floating point number, and writes a fully known immediate value to it.
public void Write(float value)
Parameters
valuefloatThe value.
Write(ushort)
Interprets the bit vector as an unsigned 16 bit integer, and writes a fully known immediate value to it.
public void Write(ushort value)
Parameters
valueushortThe value.
Write(ushort, ushort)
Interprets the bit vector as an unsigned 16 bit integer, and writes a partially known immediate value to it.
public void Write(ushort value, ushort knownMask)
Parameters
Write(uint)
Interprets the bit vector as an unsigned 32 bit integer, and writes a fully known immediate value to it.
public void Write(uint value)
Parameters
valueuintThe value.
Write(uint, uint)
Interprets the bit vector as an unsigned 32 bit integer, and writes a partially known immediate value to it.
public void Write(uint value, uint knownMask)
Parameters
Write(ulong)
Interprets the bit vector as an unsigned 64 bit integer, and writes a fully known immediate value to it.
public void Write(ulong value)
Parameters
valueulongThe value.
Write(ulong, ulong)
Interprets the bit vector as an unsigned 64 bit integer, and writes a partially known immediate value to it.
public void Write(ulong value, ulong knownMask)
Parameters
WriteBinaryString(string)
Writes a (partially known) bit string, where the least significant bit is at the end of the string, into the bit vector at the provided bit index.
public void WriteBinaryString(string binaryString)
Parameters
binaryStringstringThe binary string to write. This string may contain unknown bits (
?).
Exceptions
- ArgumentOutOfRangeException
Occurs when the bit index is not a multiple of 8.
WriteNativeInteger(long, bool)
Writes a fully known native integer into the bit vector at the provided bit index.
public void WriteNativeInteger(long value, bool is32Bit)
Parameters
valuelongThe native integer to write.
is32BitboolA value indicating whether the native integer is 32 or 64 bits wide.
Xor(BitVectorSpan)
Performs a bitwise XOR operation with another bit vector.
public void Xor(BitVectorSpan other)
Parameters
otherBitVectorSpanThe other bit vector.
Operators
implicit operator BitVectorSpan(BitVector)
Creates a span for the provided bit vector.
public static implicit operator BitVectorSpan(BitVector vector)
Parameters
vectorBitVectorThe vector.
Returns
- BitVectorSpan
The span.