Class BinaryUtil


  • public final class BinaryUtil
    extends Object

    The BinaryUtil class is a final class that provides static methods for converting binary values in string representation as bits to a Java's Primitive Data Type.

    Currently this class supports converting binary values in string representation to integer int values and integer long values.

    This class treats binary strings as bit values represented by binary digits and not real numbers. Thus, binary strings parse by this class will be converted to the suppored data types as if they were real bit values represented by binary digits.

    To treats binary values as signed or unsigned real base 2 numbers use Base2Util.

    Since:
    1.0.0.f
    • Method Detail

      • toInt

        public static final int toInt​(String input)
        Parse the input string as bits represented by binary digits to an integer int value.
        Parameters:
        input - A string to be parsed as binary digits to an interger int value.
        Returns:
        An integer int value of the binary input string.
        Throws:
        NumberFormatException - If the input string contains invalid binary digits, or if the input string contains a value that is beyond 32 bits. Leading zeroes do not count.
        EmptyStringException - If the input string is empty.
        Since:
        1.0.0.f
      • toLong

        public static final long toLong​(String input)
        Parse the input string as bits represented by binary digits to an integer long value.
        Parameters:
        input - A string to be parsed as binary digits to an interger long value.
        Returns:
        An integer long value of the binary input string.
        Throws:
        NumberFormatException - If the input string contains invalid binary digits, or if the input string contains a value that is beyond 64 bits. Leading zeroes do not count.
        EmptyStringException - If the input string is empty.
        Since:
        1.0.0.f