Class BitUtility
public static class BitUtility
- Inheritance
-
BitUtility
- Inherited Members
Methods
ByteCount(int)
Calculates the number of bytes required to store n bits.
public static int ByteCount(int n)
Parameters
n
intNumber of bits
Returns
- int
Number of bytes
ClearBit(Span<byte>, int)
public static void ClearBit(Span<byte> data, int index)
Parameters
CountBits(ReadOnlySpan<byte>)
Counts the number of set bits in a span of bytes.
public static int CountBits(ReadOnlySpan<byte> data)
Parameters
data
ReadOnlySpan<byte>Span to count bits.
Returns
- int
Count of set (one) bits.
CountBits(ReadOnlySpan<byte>, int)
Counts the number of set bits in a span of bytes starting at a specific bit index.
public static int CountBits(ReadOnlySpan<byte> data, int index)
Parameters
data
ReadOnlySpan<byte>Span to count bits.
index
intBit index to start counting from.
Returns
- int
Count of set (one) bits.
CountBits(ReadOnlySpan<byte>, int, int)
Counts the number of set bits in a span of bytes starting at a specific bit index, and limiting to a certain number of bits in the span.
public static int CountBits(ReadOnlySpan<byte> data, int index, int length)
Parameters
data
ReadOnlySpan<byte>Span to count bits.
index
intBit index to start counting from.
length
intMaximum of bits in the span to consider.
Returns
- int
Count of set (one) bits.
GetBit(byte, int)
public static bool GetBit(byte data, int index)
Parameters
Returns
GetBit(ReadOnlySpan<byte>, int)
public static bool GetBit(ReadOnlySpan<byte> data, int index)
Parameters
data
ReadOnlySpan<byte>index
int
Returns
RoundUpToMultipleOf64(long)
Rounds an integer to the nearest multiple of 64.
public static long RoundUpToMultipleOf64(long n)
Parameters
n
longInteger to round.
Returns
- long
Integer rounded to the nearest multiple of 64.
RoundUpToMultipleOf8(long)
Rounds an integer to the nearest multiple of 8.
public static long RoundUpToMultipleOf8(long n)
Parameters
n
longInteger to round.
Returns
- long
Integer rounded to the nearest multiple of 8.
RoundUpToMultiplePowerOfTwo(long, int)
Rounds an integer up to the nearest multiple of factor, where factor must be a power of two.
This function does not throw when the factor is not a power of two.
public static long RoundUpToMultiplePowerOfTwo(long n, int factor)
Parameters
Returns
- long
Integer rounded up to the nearest power of two.
SetBit(Span<byte>, int)
public static void SetBit(Span<byte> data, int index)
Parameters
SetBit(Span<byte>, int, bool)
public static void SetBit(Span<byte> data, int index, bool value)
Parameters
ToggleBit(Span<byte>, int)
public static void ToggleBit(Span<byte> data, int index)