Package convex.core.util
Class Bits
java.lang.Object
convex.core.util.Bits
Static utility function for bitwise functions
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic int
indexForDigit
(int digit, short mask) Returns the index from the present mask for the given hex digit (0-15), or -1 if not foundstatic int
leadingOnes
(long value) static int
leadingZeros
(int x) Get the number of leading zeros in the binary representation of an intstatic int
leadingZeros
(long x) Get the number of leading zeros in the binary representation of a longstatic int
lowBitMask
(int numBits) Gets a bit mask for the specified number of low bits in an intstatic int
lowBits
(int numBits, int val) Gets the specified number of low Bits in an integer.static int
positionForDigit
(int digit, short mask) Returns the array position for a given digit given a current mask.
-
Constructor Details
-
Bits
public Bits()
-
-
Method Details
-
indexForDigit
public static int indexForDigit(int digit, short mask) Returns the index from the present mask for the given hex digit (0-15), or -1 if not found- Parameters:
digit
- Hex digit (0-15)mask
- Bitmask of hex digits- Returns:
- The index of the appropriate child for this digit, or -1 if not found
-
positionForDigit
public static int positionForDigit(int digit, short mask) Returns the array position for a given digit given a current mask. If not present, this is where the new array entry must be inserted.- Parameters:
digit
- Hex digit (0-15)mask
- Bitmask of hex digits- Returns:
- Array position for the given digit in the specified mask
-
leadingZeros
public static int leadingZeros(int x) Get the number of leading zeros in the binary representation of an int- Parameters:
x
- int value to check- Returns:
- Number of leading zeros (0-32)
-
leadingZeros
public static int leadingZeros(long x) Get the number of leading zeros in the binary representation of a long- Parameters:
x
- long value to check- Returns:
- Number of leading zeros (0-64)
-
lowBitMask
public static int lowBitMask(int numBits) Gets a bit mask for the specified number of low bits in an int- Parameters:
numBits
- Number of bits to set to 1- Returns:
- int containing the specified number of set low bits
-
lowBits
public static int lowBits(int numBits, int val) Gets the specified number of low Bits in an integer. Other bits are zeroed.- Parameters:
numBits
- Number of bits to getval
- Value to extract bits from- Returns:
- Masked in with the specified number of low bits
-
leadingOnes
public static int leadingOnes(long value)
-