Table of Contents

Struct BitVectorSpan

Namespace
Echo.Memory
Assembly
Echo.dll

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

vector BitVector

The 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

bits Span<byte>

The concrete bits stored in the bit vector.

knownMask Span<byte>

The bitmask indicating which bits in bits are known.

Exceptions

ArgumentException

Occurs when the length of bits and knownMask do not match up.

Properties

Bits

Gets the raw bits stored in this bit vector span.

public Span<byte> Bits { get; }

Property Value

Span<byte>

ByteCount

Gets the number of bytes stored in the bit vector.

public int ByteCount { get; }

Property Value

int

Count

Gets the number of bits stored in the bit vector.

public int Count { get; }

Property Value

int

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

float

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

double

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

short

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

int

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

long

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

sbyte

IsFullyKnown

Gets a value indicating whether all bits in the vector are known.

public bool IsFullyKnown { get; }

Property Value

bool

IsZero

Gets a value indicating whether all bits in the vector are set to zero.

public Trilean IsZero { get; }

Property Value

Trilean

this[int]

Gets or sets a single bit in the bit vector span.

public Trilean this[int index] { get; set; }

Parameters

index int

The index of the bit to get.

Property Value

Trilean

KnownMask

Gets a bit mask indicating which bits in Bits are known.

public Span<byte> KnownMask { get; }

Property Value

Span<byte>

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

ushort

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

uint

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

ulong

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

byte

Methods

And(BitVectorSpan)

Performs a bitwise AND operation with another bit vector.

public void And(BitVectorSpan other)

Parameters

other BitVectorSpan

The 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

buffer BitVectorSpan

The bit buffer to copy the bits to.

Equals(BitVectorSpan)

Compares two BitVectorSpan's

public bool Equals(BitVectorSpan other)

Parameters

other BitVectorSpan

The 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

obj object

Returns

bool

Fill(byte)

Fills the bit vector with the repetition of a byte.

public void Fill(byte value)

Parameters

value byte

The 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

value byte

The value to fill the bit vector with.

knownMask byte

The mask indicating which bits in value are 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

other BitVectorSpan

FloatDivide(BitVectorSpan)

Interprets the bitvector as a floating point number, and divides it with another floating point number.

public void FloatDivide(BitVectorSpan other)

Parameters

other BitVectorSpan

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

other BitVectorSpan

The other floating point number.

ordered bool

A 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

other BitVectorSpan

The other floating point number.

ordered bool

A 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

other BitVectorSpan

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

other BitVectorSpan

FloatSubtract(BitVectorSpan)

Interprets the bitvector as a floating point number, and subtracts another floating point number to it.

public void FloatSubtract(BitVectorSpan other)

Parameters

other BitVectorSpan

GetHashCode()

public override int GetHashCode()

Returns

int

GetMsb()

Interprets the bit vector as an integer, and obtains the most significant bit (MSB) of the bit vector.

public Trilean GetMsb()

Returns

Trilean

IntegerAdd(BitVectorSpan)

Interprets the bit vector as an integer and adds a second integer to it.

public Trilean IntegerAdd(BitVectorSpan other)

Parameters

other BitVectorSpan

The 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

other BitVectorSpan

The 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

other BitVectorSpan

The other integer.

signed bool

Indicates 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

other BitVectorSpan

The other integer.

signed bool

Indicates 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

other BitVectorSpan

The other integer.

signed bool

Indicates 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

other BitVectorSpan

The other integer.

signed bool

Indicates 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

other BitVectorSpan

The 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

other BitVectorSpan

The 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

other BitVectorSpan

The 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

other BitVectorSpan

The 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

This is effectively clearing all bits in KnownMask. It does not change the value of Bits.

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

other BitVectorSpan

The other bit vector.

ReadNativeInteger(bool)

Reads a native integer from the vector.

public long ReadNativeInteger(bool is32Bit)

Parameters

is32Bit bool

A 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

count int

The 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

count int

The number of bits to shift with.

signExtend bool

Gets 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

bitIndex int

The 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

bitIndex int

The bit index to start the slice at.

length int

The number of bits in the slice.

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

pool BitVectorPool

The pool to rent the vector from.

Returns

BitVector

The vector.

Write(BitVectorSpan)

Writes data into the bit vector.

public void Write(BitVectorSpan data)

Parameters

data BitVectorSpan

The 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

value byte

The 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

value byte

The value.

knownMask byte

The mask indicating which bits are known.

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

value double

The 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

value short

The 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

value short

The value.

knownMask ushort

The mask indicating which bits are known.

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

value int

The 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

value int

The value.

knownMask uint

The mask indicating which bits are known.

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

value long

The 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

value long

The value.

knownMask ulong

The mask indicating which bits are known.

Write(ReadOnlySpan<byte>)

Writes fully known bytes into the bit vector.

public void Write(ReadOnlySpan<byte> data)

Parameters

data ReadOnlySpan<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

data ReadOnlySpan<byte>

The data to write.

knownMask ReadOnlySpan<byte>

The mask indicating which bits in data are known.

Exceptions

ArgumentOutOfRangeException

Occurs when the length of data and knownMask do 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

value sbyte

The 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

value sbyte

The value.

knownMask byte

The mask indicating which bits are known.

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

value float

The 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

value ushort

The 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

value ushort

The value.

knownMask ushort

The mask indicating which bits are known.

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

value uint

The 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

value uint

The value.

knownMask uint

The mask indicating which bits are known.

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

value ulong

The 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

value ulong

The value.

knownMask ulong

The mask indicating which bits are known.

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

binaryString string

The 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

value long

The native integer to write.

is32Bit bool

A 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

other BitVectorSpan

The other bit vector.

Operators

implicit operator BitVectorSpan(BitVector)

Creates a span for the provided bit vector.

public static implicit operator BitVectorSpan(BitVector vector)

Parameters

vector BitVector

The vector.

Returns

BitVectorSpan

The span.