C# 클래스 GSF.BitMath

Contains some random and useful functions.
파일 보기 프로젝트 열기: GridProtectionAlliance/gsf

공개 메소드들

메소드 설명
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