C# Класс GSF.BitMath

Contains some random and useful functions.
Показать файл Открыть проект

Открытые методы

Метод Описание
CountBitsCleared ( uint value ) : int

Counts the number of bits that are not set

CountBitsCleared ( ulong value ) : int

Counts the number of bits that are not set

CountBitsSet ( uint value ) : int

Counts the number of bits that are set

CountBitsSet ( ulong value ) : int

Counts the number of bits that are set

CountLeadingOnes ( uint value ) : int

Counts the number of consecutive 1's starting from the highest bit working down.

CountLeadingOnes ( ulong value ) : int

Counts the number of consecutive 1's starting from the highest bit working down.

CountLeadingZeros ( uint value ) : int

Counts the number of consecutive 0's starting from the highest bit working down.

Unfortunately, c# cannot call the cpu instruction clz Example from http://en.wikipedia.org/wiki/Find_first_set

CountLeadingZeros ( ulong value ) : int

Counts the number of consecutive 0's starting from the highest bit working down.

Unfortunately, c# cannot call the cpu instruction clz Example from http://en.wikipedia.org/wiki/Find_first_set

CountTrailingOnes ( uint value ) : int

Counts the number of consecutive 1's starting from the lowest bit working up.

CountTrailingOnes ( ulong value ) : int

Counts the number of consecutive 1's starting from the lowest bit working up.

CountTrailingZeros ( uint value ) : int

Counts the number of consecutive 0's starting from the lowest bit working up.

Unfortunately, c# cannot call the cpu instruction ctz Example from http://en.wikipedia.org/wiki/Find_first_set

CountTrailingZeros ( ulong value ) : int

Counts the number of consecutive 0's starting from the lowest bit working up.

Unfortunately, c# cannot call the cpu instruction ctz Example from http://en.wikipedia.org/wiki/Find_first_set

CreateBitMask ( int bitCount ) : ulong

Creates a bit mask for a number with the given number of bits.

GetClearedBitPositions ( uint value ) : IEnumerable

Returns the bit position for every bit that is cleared in the provided value. Bit positions are defined as 0-31;

GetClearedBitPositions ( ulong value ) : IEnumerable

Returns the bit position for every bit that is cleared in the provided value. Bit positions are defined as 0-63;

GetSetBitPositions ( uint value ) : IEnumerable

Returns the bit position for every bit that is set in the provided value. Bit positions are defined as 0-31;

GetSetBitPositions ( ulong value ) : IEnumerable

Returns the bit position for every bit that is set in the provided value. Bit positions are defined as 0-63;

IsPowerOfTwo ( int value ) : bool

Determines if the number is a power of 2.

IsPowerOfTwo ( long value ) : bool

Determines if the number is a power of 2.

IsPowerOfTwo ( uint value ) : bool

Determines if the number is a power of 2.

IsPowerOfTwo ( ulong value ) : bool

Determines if the number is a power of 2.

RoundDownToNearestPowerOfTwo ( uint value ) : uint

Rounds a number down to the nearest power of 2. If the value is a power of two, the same value is returned. If value is zero, 1 is returned.

RoundDownToNearestPowerOfTwo ( ulong value ) : ulong

Rounds a number down to the nearest power of 2. If the value is a power of two, the same value is returned. If value is zero, one is returned.

RoundUpToNearestPowerOfTwo ( uint value ) : uint

Rounds a number up to the nearest power of 2. If the value is a power of two, the same value is returned. If the value is larger than the largest power of 2. It is rounded down.

Method based on a method found at: http://graphics.stanford.edu/~seander/bithacks.htm Subtitle: Round up to the next highest power of 2

RoundUpToNearestPowerOfTwo ( ulong value ) : ulong

Rounds a number up to the nearest power of 2. If the value is a power of two, the same value is returned. If the value is larger than the largest power of 2. It is rounded down.

Method based on a method found at: http://graphics.stanford.edu/~seander/bithacks.htm Subtitle: Round up to the next highest power of 2

Описание методов

CountBitsCleared() публичный статический Метод

Counts the number of bits that are not set
public static CountBitsCleared ( uint value ) : int
value uint
Результат int

CountBitsCleared() публичный статический Метод

Counts the number of bits that are not set
public static CountBitsCleared ( ulong value ) : int
value ulong
Результат int

CountBitsSet() публичный статический Метод

Counts the number of bits that are set
public static CountBitsSet ( uint value ) : int
value uint
Результат int

CountBitsSet() публичный статический Метод

Counts the number of bits that are set
public static CountBitsSet ( ulong value ) : int
value ulong
Результат int

CountLeadingOnes() публичный статический Метод

Counts the number of consecutive 1's starting from the highest bit working down.
public static CountLeadingOnes ( uint value ) : int
value uint
Результат int

CountLeadingOnes() публичный статический Метод

Counts the number of consecutive 1's starting from the highest bit working down.
public static CountLeadingOnes ( ulong value ) : int
value ulong
Результат int

CountLeadingZeros() публичный статический Метод

Counts the number of consecutive 0's starting from the highest bit working down.
Unfortunately, c# cannot call the cpu instruction clz Example from http://en.wikipedia.org/wiki/Find_first_set
public static CountLeadingZeros ( uint value ) : int
value uint
Результат int

CountLeadingZeros() публичный статический Метод

Counts the number of consecutive 0's starting from the highest bit working down.
Unfortunately, c# cannot call the cpu instruction clz Example from http://en.wikipedia.org/wiki/Find_first_set
public static CountLeadingZeros ( ulong value ) : int
value ulong
Результат int

CountTrailingOnes() публичный статический Метод

Counts the number of consecutive 1's starting from the lowest bit working up.
public static CountTrailingOnes ( uint value ) : int
value uint
Результат int

CountTrailingOnes() публичный статический Метод

Counts the number of consecutive 1's starting from the lowest bit working up.
public static CountTrailingOnes ( ulong value ) : int
value ulong
Результат int

CountTrailingZeros() публичный статический Метод

Counts the number of consecutive 0's starting from the lowest bit working up.
Unfortunately, c# cannot call the cpu instruction ctz Example from http://en.wikipedia.org/wiki/Find_first_set
public static CountTrailingZeros ( uint value ) : int
value uint
Результат int

CountTrailingZeros() публичный статический Метод

Counts the number of consecutive 0's starting from the lowest bit working up.
Unfortunately, c# cannot call the cpu instruction ctz Example from http://en.wikipedia.org/wiki/Find_first_set
public static CountTrailingZeros ( ulong value ) : int
value ulong
Результат int

CreateBitMask() публичный статический Метод

Creates a bit mask for a number with the given number of bits.
public static CreateBitMask ( int bitCount ) : ulong
bitCount int
Результат ulong

GetClearedBitPositions() публичный статический Метод

Returns the bit position for every bit that is cleared in the provided value. Bit positions are defined as 0-31;
public static GetClearedBitPositions ( uint value ) : IEnumerable
value uint
Результат IEnumerable

GetClearedBitPositions() публичный статический Метод

Returns the bit position for every bit that is cleared in the provided value. Bit positions are defined as 0-63;
public static GetClearedBitPositions ( ulong value ) : IEnumerable
value ulong
Результат IEnumerable

GetSetBitPositions() публичный статический Метод

Returns the bit position for every bit that is set in the provided value. Bit positions are defined as 0-31;
public static GetSetBitPositions ( uint value ) : IEnumerable
value uint
Результат IEnumerable

GetSetBitPositions() публичный статический Метод

Returns the bit position for every bit that is set in the provided value. Bit positions are defined as 0-63;
public static GetSetBitPositions ( ulong value ) : IEnumerable
value ulong
Результат IEnumerable

IsPowerOfTwo() публичный статический Метод

Determines if the number is a power of 2.
If is less than zero
public static IsPowerOfTwo ( int value ) : bool
value int The value to check power of two properties
Результат bool

IsPowerOfTwo() публичный статический Метод

Determines if the number is a power of 2.
If is less than zero
public static IsPowerOfTwo ( long value ) : bool
value long The value to check power of two properties
Результат bool

IsPowerOfTwo() публичный статический Метод

Determines if the number is a power of 2.
public static IsPowerOfTwo ( uint value ) : bool
value uint The value to check power of two properties
Результат bool

IsPowerOfTwo() публичный статический Метод

Determines if the number is a power of 2.
public static IsPowerOfTwo ( ulong value ) : bool
value ulong The value to check power of two properties
Результат bool

RoundDownToNearestPowerOfTwo() публичный статический Метод

Rounds a number down to the nearest power of 2. If the value is a power of two, the same value is returned. If value is zero, 1 is returned.
public static RoundDownToNearestPowerOfTwo ( uint value ) : uint
value uint
Результат uint

RoundDownToNearestPowerOfTwo() публичный статический Метод

Rounds a number down to the nearest power of 2. If the value is a power of two, the same value is returned. If value is zero, one is returned.
public static RoundDownToNearestPowerOfTwo ( ulong value ) : ulong
value ulong
Результат ulong

RoundUpToNearestPowerOfTwo() публичный статический Метод

Rounds a number up to the nearest power of 2. If the value is a power of two, the same value is returned. If the value is larger than the largest power of 2. It is rounded down.
Method based on a method found at: http://graphics.stanford.edu/~seander/bithacks.htm Subtitle: Round up to the next highest power of 2
public static RoundUpToNearestPowerOfTwo ( uint value ) : uint
value uint
Результат uint

RoundUpToNearestPowerOfTwo() публичный статический Метод

Rounds a number up to the nearest power of 2. If the value is a power of two, the same value is returned. If the value is larger than the largest power of 2. It is rounded down.
Method based on a method found at: http://graphics.stanford.edu/~seander/bithacks.htm Subtitle: Round up to the next highest power of 2
public static RoundUpToNearestPowerOfTwo ( ulong value ) : ulong
value ulong
Результат ulong