Class JavaBigIntegerParser

java.lang.Object
ch.randelshofer.fastdoubleparser.JavaBigIntegerParser

public final class JavaBigIntegerParser extends Object
Parses a BigInteger value; the supported syntax is compatible with BigInteger(String, int).

Syntax

Formal specification of the grammar:

BigIntegerString:
[Sign] Digits
Sign:
(one of)
+ -
Digits:
Digit {Digit}
Digit:
(one of)
0 1 2 3 4 5 6 7 8 9
a b c d e f g h i j k l m n o p q r s t u v w x y z
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Character lengths accepted by BigInteger(String):

  • BigIntegerString: Integer.MAX_VALUE - 4.

    If the significand consists only of zero digits, the length is only limited by the maximal supported length of a Java array.

  • radix=10

    If the significand contains at least one non-zero digit, the length is limited to index of first non-zero digit + 646_456_993. This is because the resulting value must fit into 2^31 - 1 bits. The decimal representation of the value 2^31 - 1 needs 646,456,993 digits. Therefore an input String can only contain up to that many significant digits - the remaining digits must be leading zeroes.

  • radix=16

    If the significand contains at least one non-zero digit, the length is limited to index of first non-zero digit + 536_870_912. This is because the resulting value must fit into 2^31 - 1 bits. The hexa-decimal representation of the value 2^31 - 1 needs 536,870,912 digits. Therefore an input String can only contain up to that many significant digits - the remaining digits must be leading zeroes.

References:

Java SE 17 & JDK 17, JavaDoc, Class BigInteger
docs.oracle.com
  • Method Details

    • parseBigInteger

      public static BigInteger parseBigInteger(CharSequence str)
      Convenience method for calling parseBigInteger(CharSequence, int, int).
      Parameters:
      str - the string to be parsed
      Returns:
      the parsed value
      Throws:
      NullPointerException - if the string is null
      NumberFormatException - if the string can not be parsed successfully
    • parseBigInteger

      public static BigInteger parseBigInteger(CharSequence str, int radix)
      Convenience method for calling parseBigInteger(CharSequence, int, int, int).
      Parameters:
      str - the string to be parsed
      radix - the radix to be used in interpreting the str
      Returns:
      the parsed value
      Throws:
      NullPointerException - if the string is null
      NumberFormatException - if the string can not be parsed successfully
    • parseBigInteger

      public static BigInteger parseBigInteger(CharSequence str, int offset, int length)
      Convenience method for calling parseBigInteger(CharSequence, int, int, int).
      Parameters:
      str - the string to be parsed
      offset - The index of the first character to parse
      length - The number of characters to parse
      Returns:
      the parsed value
      Throws:
      NullPointerException - if the string is null
      IllegalArgumentException - if offset or length are illegal
      NumberFormatException - if the string can not be parsed successfully
    • parseBigInteger

      public static BigInteger parseBigInteger(CharSequence str, int offset, int length, int radix)
      Parses a BigIntegerString from a CharSequence and converts it into a BigInteger value.
      Parameters:
      str - the string to be parsed
      offset - The index of the first character to parse
      length - The number of characters to parse
      radix - the radix to be used in interpreting the str
      Returns:
      the parsed value
      Throws:
      NullPointerException - if the string is null
      IllegalArgumentException - if offset or length are illegal
      NumberFormatException - if the string can not be parsed successfully
    • parseBigInteger

      public static BigInteger parseBigInteger(byte[] str)
      Convenience method for calling parseBigInteger(byte[], int, int).
      Parameters:
      str - the string to be parsed
      Returns:
      the parsed value
      Throws:
      NullPointerException - if the string is null
      NumberFormatException - if the string can not be parsed successfully
    • parseBigInteger

      public static BigInteger parseBigInteger(byte[] str, int radix)
      Convenience method for calling parseBigInteger(byte[], int, int, int).
      Parameters:
      str - the string to be parsed
      radix - the radix to be used in interpreting the str
      Returns:
      the parsed value
      Throws:
      NullPointerException - if the string is null
      NumberFormatException - if the string can not be parsed successfully
    • parseBigInteger

      public static BigInteger parseBigInteger(byte[] str, int offset, int length)
      Parses a BigIntegerString from a byte-Array and converts it into a BigInteger value.

      See JsonDoubleParser for the syntax of FloatingPointLiteral.

      Parameters:
      str - the string to be parsed, a byte array with characters in ISO-8859-1, ASCII or UTF-8 encoding
      offset - The index of the first character to parse
      length - The number of characters to parse
      Returns:
      the parsed value
      Throws:
      NullPointerException - if the string is null
      IllegalArgumentException - if offset or length are illegal
      NumberFormatException - if the string can not be parsed successfully
    • parseBigInteger

      public static BigInteger parseBigInteger(byte[] str, int offset, int length, int radix)
      Parses a BigIntegerString from a byte-Array and converts it into a BigInteger value.

      See JsonDoubleParser for the syntax of FloatingPointLiteral.

      Parameters:
      str - the string to be parsed, a byte array with characters in ISO-8859-1, ASCII or UTF-8 encoding
      offset - The index of the first character to parse
      length - The number of characters to parse
      radix - the radix to be used in interpreting the str
      Returns:
      the parsed value
      Throws:
      NullPointerException - if the string is null
      IllegalArgumentException - if offset or length are illegal
      NumberFormatException - if the string can not be parsed successfully
    • parseBigInteger

      public static BigInteger parseBigInteger(char[] str)
      Convenience method for calling parseBigInteger(char[], int, int).
      Parameters:
      str - the string to be parsed
      Returns:
      the parsed value
      Throws:
      NullPointerException - if the string is null
      NumberFormatException - if the string can not be parsed successfully
    • parseBigInteger

      public static BigInteger parseBigInteger(char[] str, int radix)
      Convenience method for calling parseBigInteger(char[], int, int, int).
      Parameters:
      str - the string to be parsed
      radix - the radix to be used in interpreting the str
      Returns:
      the parsed value
      Throws:
      NullPointerException - if the string is null
      NumberFormatException - if the string can not be parsed successfully
    • parseBigInteger

      public static BigInteger parseBigInteger(char[] str, int offset, int length)
      Parses a BigIntegerString from a char-Array and converts it into a BigInteger value.

      See JsonDoubleParser for the syntax of FloatingPointLiteral.

      Parameters:
      str - the string to be parsed, a byte array with characters in ISO-8859-1, ASCII or UTF-8 encoding
      offset - The index of the first character to parse
      length - The number of characters to parse
      Returns:
      the parsed value
      Throws:
      NullPointerException - if the string is null
      IllegalArgumentException - if offset or length are illegal
      NumberFormatException - if the string can not be parsed successfully
    • parseBigInteger

      public static BigInteger parseBigInteger(char[] str, int offset, int length, int radix)
      Parses a BigIntegerString from a char-Array and converts it into a BigInteger value.

      See JsonDoubleParser for the syntax of FloatingPointLiteral.

      Parameters:
      str - the string to be parsed, a byte array with characters in ISO-8859-1, ASCII or UTF-8 encoding
      offset - The index of the first character to parse
      length - The number of characters to parse
      radix - the radix to be used in interpreting the str
      Returns:
      the parsed value
      Throws:
      NullPointerException - if the string is null
      IllegalArgumentException - if offset or length are illegal
      NumberFormatException - if the string can not be parsed successfully