Class NumberUtil


  • public class NumberUtil
    extends Object
    A collection of utilities to work with numbers.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static double LOGE_2  
    • Constructor Summary

      Constructors 
      Constructor Description
      NumberUtil()  
    • Constructor Detail

      • NumberUtil

        public NumberUtil()
    • Method Detail

      • log2

        public static double log2​(double value)
        Computes the log2 (log-base-two) of the specified value.
        Parameters:
        value - the double for which the log2 is desired.
        Returns:
        the log2 of the specified value
      • toHex

        public static String toHex​(byte[] bytes,
                                   int offset,
                                   int cnt)
        Converts the specified array of bytes into a string of hex characters (low byte first).
        Parameters:
        bytes - the array of bytes that are to be converted. This cannot be null though it may be empty.
        offset - the offset in bytes at which the bytes will be taken. This cannot be negative and must be less than bytes.length - 1.
        cnt - the number of bytes to be retrieved from the specified array. This cannot be negative. If greater than bytes.length - offset then that value is used.
        Returns:
        a string of at most count characters that represents the specified byte array in hex. This will never be null though it may be empty if bytes is empty or count is zero.
        Throws:
        IllegalArgumentException - if offset is greater than or equal to bytes.length.
        See Also:
        fromHex(String, int, int)
      • fromHex

        public static byte[] fromHex​(String string,
                                     int offset,
                                     int count)
        Converts the specified array of hex characters into an array of bytes (low byte first).
        Parameters:
        string - the string of hex characters to be converted into bytes. This cannot be null though it may be blank.
        offset - the offset in the string at which the characters will be taken. This cannot be negative and must be less than string.length() - 1.
        count - the number of characters to be retrieved from the specified string. This cannot be negative and must be divisible by two (since there are two characters per byte).
        Returns:
        the array of bytes that were converted from the specified string (in the specified range). This will never be null though it may be empty if string is empty or count is zero.
        Throws:
        IllegalArgumentException - if offset is greater than or equal to string.length() or if count is not divisible by two.
        See Also:
        toHex(byte[], int, int)