Class BitArray
A simple, fast array of bits, represented compactly by an array of ints internally.
public sealed class BitArray
- Inheritance
-
BitArray
- Inherited Members
Constructors
BitArray()
default constructor
public BitArray()
BitArray(int)
initializing constructor
public BitArray(int size)
Parameters
size
intdesired size of the array
Properties
Array
public int[] Array { get; }
Property Value
- int[]
underlying array of ints. The first element holds the first 32 bits, and the least significant bit is bit 0.
this[int]
index accessor
public bool this[int i] { get; set; }
Parameters
i
int
Property Value
Size
size of the array, number of elements
public int Size { get; }
Property Value
SizeInBytes
size of the array in bytes
public int SizeInBytes { get; }
Property Value
Methods
Clone()
Erstellt ein neues Objekt, das eine Kopie der aktuellen Instanz darstellt.
public object Clone()
Returns
- object
Ein neues Objekt, das eine Kopie dieser Instanz darstellt.
Equals(object)
Determines whether the specified object is equal to this instance.
public override bool Equals(object o)
Parameters
Returns
GetHashCode()
Returns a hash code for this instance.
public override int GetHashCode()
Returns
- int
A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
ToString()
Returns a string that represents this instance.
public override string ToString()
Returns
appendBit(bool)
Appends the bit.
public void appendBit(bool bit)
Parameters
bit
boolThe bit.
appendBitArray(BitArray)
adds the array to the end
public void appendBitArray(BitArray other)
Parameters
other
BitArray
appendBits(int, int)
Appends the least-significant bits, from value, in order from most-significant to least-significant. For example, appending 6 bits from 0x000001E will append the bits 0, 1, 1, 1, 1, 0 in that order.
public void appendBits(int value, int numBits)
Parameters
clear()
Clears all bits (sets to false).
public void clear()
flip(int)
Flips bit i.
public void flip(int i)
Parameters
i
intbit to set
getNextSet(int)
Gets the next set.
public int getNextSet(int from)
Parameters
from
intfirst bit to check
Returns
- int
index of first bit that is set, starting from the given index, or size if none are set at or beyond this given index
getNextUnset(int)
see getNextSet(int)
public int getNextUnset(int from)
Parameters
from
intindex to start looking for unset bit
Returns
isRange(int, int, bool)
Efficient method to check if a range of bits is set, or not set.
public bool isRange(int start, int end, bool value)
Parameters
start
intstart of range, inclusive.
end
intend of range, exclusive
value
boolif true, checks that bits in range are set, otherwise checks that they are not set
Returns
- bool
true iff all bits are set or not set in range, according to value argument
reverse()
Reverses all bits in the array.
public void reverse()
setBulk(int, int)
Sets a block of 32 bits, starting at bit i.
public void setBulk(int i, int newBits)
Parameters
i
intfirst bit to set
newBits
intthe new value of the next 32 bits. Note again that the least-significant bit corresponds to bit i, the next-least-significant to i+1, and so on.
setRange(int, int)
Sets a range of bits.
public void setRange(int start, int end)
Parameters
toBytes(int, byte[], int, int)
converts to bytes.
public void toBytes(int bitOffset, byte[] array, int offset, int numBytes)
Parameters
bitOffset
intfirst bit to start writing
array
byte[]array to write into. Bytes are written most-significant byte first. This is the opposite of the internal representation, which is exposed by BitArray
offset
intposition in array to start writing
numBytes
inthow many bytes to write
xor(BitArray)
XOR operation
public void xor(BitArray other)
Parameters
other
BitArray