Class Bits

java.lang.Object
convex.core.util.Bits

public class Bits extends Object
Static utility function for bitwise functions
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    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
    static int
    leadingZeros(int x)
    Get the number of leading zeros in the binary representation of an int
    static int
    leadingZeros(long x)
    Get the number of leading zeros in the binary representation of a long
    static int
    lowBitMask(int numBits)
    Gets a bit mask for the specified number of low bits in an int
    static 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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 get
      val - Value to extract bits from
      Returns:
      Masked in with the specified number of low bits