Early Preview

This is currently very much a preview. Please feel free to try things out, but don't be upset if anything is not yet working. Feedback is welcome over on our GitHub Dicussions page.

class System.​Numerics.​BitOperations

Assembly: System.Runtime

Inheritance: object → BitOperations

Provides utility methods for intrinsic bit-twiddling operations. The methods use hardware intrinsics when available on the underlying platform; otherwise, they use optimized software fallbacks.

Methods

public static uint
Crc32C​(uint crc, byte data)
Accumulates the CRC (Cyclic redundancy check) checksum.
Returns The CRC-checksum.
crc The base value to calculate checksum on.
data The data for which to compute the checksum.
public static uint
Crc32C​(uint crc, ushort data)
Accumulates the CRC (Cyclic redundancy check) checksum.
Returns The CRC-checksum.
crc The base value to calculate checksum on.
data The data for which to compute the checksum.
public static uint
Crc32C​(uint crc, uint data)
Accumulates the CRC (Cyclic redundancy check) checksum.
Returns The CRC-checksum.
crc The base value to calculate checksum on.
data The data for which to compute the checksum.
public static uint
Crc32C​(uint crc, ulong data)
Accumulates the CRC (Cyclic redundancy check) checksum.
Returns The CRC-checksum.
crc The base value to calculate checksum on.
data The data for which to compute the checksum.
public static bool
IsPow2​(int value)
Evaluates whether the specified <see cref="T:System.Int32" /> value is a power of two.
Returns <see langword="true" /> if the specified value is a power of two; <see langword="false" /> otherwise.
value The value to evaluate as being a power of two.
public static bool
IsPow2​(long value)
Evaluates whether the specified <see cref="T:System.Int64" /> value is a power of two.
Returns <see langword="true" /> if the specified value is a power of two; <see langword="false" /> otherwise.
value The value to evaluate as being a power of two.
public static bool
IsPow2​(nint value)
Determines whether the specified integral value is a power of 2.
Returns <see langword="true" /> if the value is a power of 2; <see langword="false" /> otherwise.
value The value.
public static bool
IsPow2​(uint value)
Evaluates whether the specified <see cref="T:System.UInt32" /> value is a power of two.
Returns <see langword="true" /> if the specified value is a power of two; <see langword="false" /> otherwise.
value The value to evaluate as being a power of two.
public static bool
IsPow2​(ulong value)
Evaluates whether the specified <see cref="T:System.UInt64" /> value is a power of two.
Returns <see langword="true" /> if the specified value is a power of two; <see langword="false" /> otherwise.
value The value to evaluate as being a power of two.
public static bool
IsPow2​(UIntPtr value)
Determines whether the specified integral value is a power of 2.
Returns <see langword="true" /> if the value is a power of 2; <see langword="false" /> otherwise.
value The value.
public static int
LeadingZeroCount​(uint value)
Counts the number of leading zero bits in an unsigned 32-bit integer mask.
Returns The number of leading zero bits in a mask.
value The mask.
public static int
LeadingZeroCount​(ulong value)
Counts the number of leading zero bits in an unsigned 64-bit integer mask.
Returns The number of leading zero bits in a mask.
value The mask.
public static int
LeadingZeroCount​(UIntPtr value)
Counts the number of leading zero bits in a mask. Similar in behavior to the x86 instruction LZCNT.
Returns The count of leading zeros bits in a mask.
value The value.
public static int
Log2​(uint value)
Returns the integer (floor) log of the specified value, base 2.
Returns The log of the specified value, base 2.
value The number from which to obtain the logarithm.
public static int
Log2​(ulong value)
Returns the integer (floor) log of the specified value, base 2.
Returns The log of the specified value, base 2.
value The number from which to obtain the logarithm.
public static int
Log2​(UIntPtr value)
Returns the integer (floor) log of the specified value, base 2.
Returns The logarithm value.
value The value.
public static int
PopCount​(uint value)
Returns the population count (number of bits set) of a mask.
Returns The population count of a mask.
value The mask.
public static int
PopCount​(ulong value)
Returns the population count (number of bits set) of an unsigned 64-bit integer mask.
Returns The population count of the mask.
value The mask.
public static int
PopCount​(UIntPtr value)
Returns the population count (number of bits set) of a mask. Similar in behavior to the x86 instruction POPCNT.
Returns The population count.
value The value.
public static uint
RotateLeft​(uint value, int offset)
Rotates the specified value left by the specified number of bits.
Returns The rotated value.
value The value to rotate.
offset The number of bits to rotate by. Any value outside the range [0..31] is treated as congruent mod 32.
public static ulong
RotateLeft​(ulong value, int offset)
Rotates the specified value left by the specified number of bits.
Returns The rotated value.
value The value to rotate.
offset The number of bits to rotate by. Any value outside the range [0..63] is treated as congruent mod 64.
public static UIntPtr
RotateLeft​(UIntPtr value, int offset)
Rotates the specified value left by the specified number of bits. Similar in behavior to the x86 instruction ROL.
Returns The rotated value.
value The value to rotate.
offset The number of bits to rotate by. Any value outside the range [0..31] is treated as congruent mod 32 on a 32-bit process, and any value outside the range [0..63] is treated as congruent mod 64 on a 64-bit process.
public static uint
RotateRight​(uint value, int offset)
Rotates the specified value right by the specified number of bits.
Returns The rotated value.
value The value to rotate.
offset The number of bits to rotate by. Any value outside the range [0..31] is treated as congruent mod 32.
public static ulong
RotateRight​(ulong value, int offset)
Rotates the specified value right by the specified number of bits.
Returns The rotated value.
value The value to rotate.
offset The number of bits to rotate by. Any value outside the range [0..63] is treated as congruent mod 64.
public static UIntPtr
RotateRight​(UIntPtr value, int offset)
Rotates the specified value right by the specified number of bits. Similar in behavior to the x86 instruction ROR.
Returns The rotated value.
value The value to rotate.
offset The number of bits to rotate by. Any value outside the range [0..31] is treated as congruent mod 32 on a 32-bit process, and any value outside the range [0..63] is treated as congruent mod 64 on a 64-bit process.
public static uint
RoundUpToPowerOf2​(uint value)
Rounds the specified <see cref="T:System.UInt32" /> value up to a power of two.
Returns The smallest power of two that's greater than or equal to <paramref name="value" /> . If <paramref name="value" /> is 0 or the result overflows, returns 0.
value The value to round up to a power of two.
public static ulong
RoundUpToPowerOf2​(ulong value)
Rounds the specified <see cref="T:System.UInt64" /> value up to a power of two.
Returns The smallest power of two that's greater than or equal to <paramref name="value" /> . If <paramref name="value" /> is 0 or the result overflows, returns 0.
value The value to round up to a power of two.
public static UIntPtr
RoundUpToPowerOf2​(UIntPtr value)
Rounds the given integral value up to a power of 2.
Returns The smallest power of 2 that is greater than or equal to <paramref name="value" /> . If <paramref name="value" /> is 0 or the result overflows, returns 0.
value The value.
public static int
TrailingZeroCount​(int value)
Counts the number of trailing zero bits in an 32-bit integer value mask.
Returns The number of trailing zero bits in the integer value.
value The mask.
public static int
TrailingZeroCount​(long value)
Counts the number of trailing zero bits in a 64-bit integer value mask.
Returns The number of trailing zero bits in the mask.
value The mask.
public static int
TrailingZeroCount​(nint value)
Counts the number of trailing zero bits in a mask. Similar in behavior to the x86 instruction TZCNT.
Returns The count of trailing zero bits in a mask.
value The value.
public static int
TrailingZeroCount​(uint value)
Counts the number of trailing zero bits in an unsigned 32-bit integer value mask.
Returns The number of trailing zero bits in the mask.
value The mask.
public static int
TrailingZeroCount​(ulong value)
Count the number of trailing zero bits in an unsigned 64-bit integer value mask.
Returns The number of trailing zero bits in the mask.
value The mask.
public static int
TrailingZeroCount​(UIntPtr value)
Counts the number of trailing zero bits in a mask. Similar in behavior to the x86 instruction TZCNT.
Returns The count of trailing zero bits in a mask.
value The value.
public bool
Equals​(object obj)
Inherited from object
Determines whether the specified object is equal to the current object.
Returns <see langword="true" /> if the specified object is equal to the current object; otherwise, <see langword="false" /> .
obj The object to compare with the current object.
protected void
Finalize​()
Inherited from object
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
public int
GetHashCode​()
Inherited from object
Serves as the default hash function.
Returns A hash code for the current object.
public Type
GetType​()
Inherited from object
Gets the <see cref="T:System.Type" /> of the current instance.
Returns The exact runtime type of the current instance.
protected object
MemberwiseClone​()
Inherited from object
Creates a shallow copy of the current <see cref="T:System.Object" /> .
Returns A shallow copy of the current <see cref="T:System.Object" /> .
public string
ToString​()
Inherited from object
Returns a string that represents the current object.
Returns A string that represents the current object.