| java.lang.Object | ||
| ↳ | java.lang.Number | |
| ↳ | java.math.BigInteger | |
An immutable signed integer of arbitrary magnitude.
BitSet for high-performance bitwise operations on arbitrarily-large sequences of bits. 
       
     | Fields | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|  | ONE | The BigIntegerconstant 1. | |||||||||
|  | TEN | The BigIntegerconstant 10. | |||||||||
|  | ZERO | The BigIntegerconstant 0. | |||||||||
| Public Constructors | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|  | 
           Constructs a random non-negative 
            BigIntegerinstance in the range[0, pow(2, numBits)-1]. | ||||||||||
|  | 
           Constructs a random 
            BigIntegerinstance in the range[0, pow(2, bitLength)-1]which is probably prime. | ||||||||||
|  | 
           Constructs a new 
            BigIntegerby parsingvalue. | ||||||||||
|  | 
           Constructs a new 
            BigIntegerinstance by parsingvalue. | ||||||||||
|  | 
           Constructs a new 
            BigIntegerinstance with the given sign and magnitude. | ||||||||||
|  | 
           Constructs a new 
            BigIntegerfrom the given two's complement representation. | ||||||||||
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|  | 
           Returns a 
            BigIntegerwhose value is the absolute value ofthis. | ||||||||||
|  | 
           Returns a 
            BigIntegerwhose value isthis + value. | ||||||||||
|  | 
           Returns a 
            BigIntegerwhose value isthis & value. | ||||||||||
|  | 
           Returns a 
            BigIntegerwhose value isthis & ~value. | ||||||||||
|  | 
           Returns the number of bits in the two's complement representation of 
            thiswhich differ from the sign bit. | ||||||||||
|  | 
           Returns the length of the value's two's complement representation without leading zeros for positive numbers / without leading ones for negative values.
           | ||||||||||
|  | 
           Returns a 
            BigIntegerwhich has the same binary representation asthisbut with the bit at position n cleared. | ||||||||||
|  | 
           Compares this 
            BigIntegerwithvalue. | ||||||||||
|  | 
           Returns a 
            BigIntegerwhose value isthis / divisor. | ||||||||||
|  | 
           Returns a two element 
            BigIntegerarray containingthis / divisorat index 0 andthis % divisorat index 1. | ||||||||||
|  | 
           Returns this 
            BigIntegeras a double. | ||||||||||
|  | 
           Compares this instance with the specified object and indicates if they are equal.
           | ||||||||||
|  | 
           Returns a 
            BigIntegerwhich has the same binary representation asthisbut with the bit at position n flipped. | ||||||||||
|  | 
           Returns this 
            BigIntegeras a float. | ||||||||||
|  | 
           Returns a 
            BigIntegerwhose value is greatest common divisor ofthisandvalue. | ||||||||||
|  | 
           Returns the position of the lowest set bit in the two's complement representation of this 
            BigInteger. | ||||||||||
|  | 
           Returns an integer hash code for this object.
           | ||||||||||
|  | 
           Returns this 
            BigIntegeras an int value. | ||||||||||
|  | 
           Tests whether this 
            BigIntegeris probably prime. | ||||||||||
|  | 
           Returns this 
            BigIntegeras a long value. | ||||||||||
|  | 
           Returns the maximum of this 
            BigIntegerandvalue. | ||||||||||
|  | 
           Returns the minimum of this 
            BigIntegerandvalue. | ||||||||||
|  | 
           Returns a 
            BigIntegerwhose value isthis mod m. | ||||||||||
|  | 
           Returns a 
            BigIntegerwhose value is1/this mod m. | ||||||||||
|  | 
           Returns a 
            BigIntegerwhose value ispow(this, exponent) mod m. | ||||||||||
|  | 
           Returns a 
            BigIntegerwhose value isthis * value. | ||||||||||
|  | 
           Returns a 
            BigIntegerwhose value is the-this. | ||||||||||
|  | 
           Returns the smallest integer x > 
            thiswhich is probably prime as aBigIntegerinstance. | ||||||||||
|  | 
           Returns a 
            BigIntegerwhose value is~this. | ||||||||||
|  | 
           Returns a 
            BigIntegerwhose value isthis | value. | ||||||||||
|  | 
           Returns a 
            BigIntegerwhose value ispow(this, exp). | ||||||||||
|  | 
           Returns a random positive 
            BigIntegerinstance in the range[0, pow(2, bitLength)-1]which is probably prime. | ||||||||||
|  | 
           Returns a 
            BigIntegerwhose value isthis % divisor. | ||||||||||
|  | 
           Returns a 
            BigIntegerwhich has the same binary representation asthisbut with the bit at position n set. | ||||||||||
|  | 
           Returns a 
            BigIntegerwhose value isthis << n. | ||||||||||
|  | 
           Returns a 
            BigIntegerwhose value isthis >> n. | ||||||||||
|  | 
           Returns the sign of this 
            BigInteger. | ||||||||||
|  | 
           Returns a 
            BigIntegerwhose value isthis - value. | ||||||||||
|  | 
           Tests whether the bit at position n in 
            thisis set. | ||||||||||
|  | 
           Returns the two's complement representation of this 
            BigIntegerin a byte array. | ||||||||||
|  | 
           Returns a string representation of this 
            BigIntegerin decimal form. | ||||||||||
|  | 
           Returns a string containing a string representation of this 
            BigIntegerwith base radix. | ||||||||||
|  | 
           Returns a 
            BigIntegerwhose value is equal tovalue. | ||||||||||
|  | 
           Returns a 
            BigIntegerwhose value isthis ^ value. | ||||||||||
| [Expand] 
           Inherited Methods
           | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|  From class java.lang.Number | |||||||||||
|  From class java.lang.Object | |||||||||||
|  From interface java.lang.Comparable | |||||||||||
Constructs a random non-negative BigInteger instance in the range [0, pow(2, numBits)-1].
| numBits | maximum length of the new BigIntegerin bits. | 
|---|---|
| random | is the random number generator to be used. | 
| IllegalArgumentException | if numBits< 0. | 
|---|
Constructs a random BigInteger instance in the range [0, pow(2, bitLength)-1] which is probably prime. The probability that the returned BigInteger is prime is beyond 1 - 1/pow(2, certainty). 
Implementation Note: the Random argument is ignored. This implementation uses OpenSSL's bn_rand as a source of cryptographically strong pseudo-random numbers.
| bitLength | length of the new BigIntegerin bits. | 
|---|---|
| certainty | tolerated primality uncertainty. | 
| ArithmeticException | if bitLength < 2. | 
|---|
Constructs a new BigInteger by parsing value. The string representation consists of an optional plus or minus sign followed by a non-empty sequence of decimal digits. Digits are interpreted as if by Character.digit(char,10).
| value | string representation of the new BigInteger. | 
|---|
| NullPointerException | if value == null. | 
|---|---|
| NumberFormatException | if valueis not a valid representation of aBigInteger. | 
Constructs a new BigInteger instance by parsing value. The string representation consists of an optional plus or minus sign followed by a non-empty sequence of digits in the specified radix. Digits are interpreted as if by Character.digit(char, radix).
| value | string representation of the new BigInteger. | 
|---|---|
| radix | the base to be used for the conversion. | 
| NullPointerException | if value == null. | 
|---|---|
| NumberFormatException | if valueis not a valid representation of aBigIntegeror ifradix < Character.MIN_RADIXorradix > Character.MAX_RADIX. | 
Constructs a new BigInteger instance with the given sign and magnitude.
| signum | sign of the new BigInteger(-1 for negative, 0 for zero, 1 for positive). | 
|---|---|
| magnitude | magnitude of the new BigIntegerwith the most significant byte first. | 
| NullPointerException | if magnitude == null. | 
|---|---|
| NumberFormatException | if the sign is not one of -1, 0, 1 or if the sign is zero and the magnitude contains non-zero entries. | 
Constructs a new BigInteger from the given two's complement representation. The most significant byte is the entry at index 0. The most significant bit of this entry determines the sign of the new BigInteger instance. The array must be nonempty.
| value | two's complement representation of the new BigInteger. | 
|---|
| NullPointerException | if value == null. | 
|---|---|
| NumberFormatException | if the length of valueis zero. | 
Returns a BigInteger whose value is the absolute value of this. 
Returns a BigInteger whose value is this + value. 
Returns a BigInteger whose value is this & value. 
Implementation Note: Usage of this method is not recommended as the current implementation is not efficient.
| value | value to be and'ed with this. | 
|---|
| NullPointerException | if value == null. | 
|---|
Returns a BigInteger whose value is this & ~value. Evaluating x.andNot(value) returns the same result as x.and(value.not()). 
Implementation Note: Usage of this method is not recommended as the current implementation is not efficient.
| value | value to be not'ed and then and'ed with this. | 
|---|
| NullPointerException | if value == null. | 
|---|
Returns the number of bits in the two's complement representation of this which differ from the sign bit. If this is negative, the result is equivalent to the number of bits set in the two's complement representation of -this - 1. 
Use bitLength(0) to find the length of the binary value in bits. 
Implementation Note: Usage of this method is not recommended as the current implementation is not efficient.
Returns the length of the value's two's complement representation without leading zeros for positive numbers / without leading ones for negative values.
The two's complement representation of this will be at least bitLength() + 1 bits long. 
The value will fit into an int if bitLength() < 32 or into a long if bitLength() < 64.
this without the sign bit. Returns a BigInteger which has the same binary representation as this but with the bit at position n cleared. The result is equivalent to this & ~pow(2, n). 
Implementation Note: Usage of this method is not recommended as the current implementation is not efficient.
| n | position where the bit in thishas to be cleared. | 
|---|
| ArithmeticException | if n < 0. | 
|---|
Compares this BigInteger with value. Returns -1 if this < value, 0 if this == value and 1 if this > value, .
| value | value to be compared with this. | 
|---|
| NullPointerException | if value == null. | 
|---|
Returns a BigInteger whose value is this / divisor.
| divisor | value by which thisis divided. | 
|---|
this / divisor.| NullPointerException | if divisor == null. | 
|---|---|
| ArithmeticException | if divisor == 0. | 
Returns a two element BigInteger array containing this / divisor at index 0 and this % divisor at index 1.
| divisor | value by which thisis divided. | 
|---|
| NullPointerException | if divisor == null. | 
|---|---|
| ArithmeticException | if divisor == 0. | 
Returns this BigInteger as a double. If this is too big to be represented as a double, then Double.POSITIVE_INFINITY or Double.NEGATIVE_INFINITY is returned. Note that not all integers in the range [-Double.MAX_VALUE, Double.MAX_VALUE] can be exactly represented as a double. 
Compares this instance with the specified object and indicates if they are equal. In order to be equal, o must represent the same object as this instance using a class-specific comparison. The general contract is that this comparison should be reflexive, symmetric, and transitive. Also, no object reference other than null is equal to null. 
The default implementation returns true only if this == o. See Writing a correct equals method if you intend implementing your own equals method. 
The general contract for the equals and hashCode() methods is that if equals returns true for any two objects, then hashCode() must return the same value for these objects. This means that subclasses of Object usually override either both methods or neither of them.
| x | the object to compare this instance with. | 
|---|
true if the specified object is equal to this Object; false otherwise.Returns a BigInteger which has the same binary representation as this but with the bit at position n flipped. The result is equivalent to this ^ pow(2, n). 
Implementation Note: Usage of this method is not recommended as the current implementation is not efficient.
| n | position where the bit in thishas to be flipped. | 
|---|
| ArithmeticException | if n < 0. | 
|---|
Returns this BigInteger as a float. If this is too big to be represented as a float, then Float.POSITIVE_INFINITY or Float.NEGATIVE_INFINITY is returned. Note that not all integers in the range [-Float.MAX_VALUE, Float.MAX_VALUE] can be exactly represented as a float. 
Returns a BigInteger whose value is greatest common divisor of this and value. If this == 0 and value == 0 then zero is returned, otherwise the result is positive.
| value | value with which the greatest common divisor is computed. | 
|---|
| NullPointerException | if value == null. | 
|---|
Returns the position of the lowest set bit in the two's complement representation of this BigInteger. If all bits are zero (this==0) then -1 is returned as result. 
Implementation Note: Usage of this method is not recommended as the current implementation is not efficient.
Returns an integer hash code for this object. By contract, any two objects for which equals(Object) returns true must return the same hash code value. This means that subclasses of Object usually override both methods or neither method. 
Note that hash values must not change over time unless information used in equals comparisons also changes.
See Writing a correct hashCode method if you intend implementing your own hashCode method.
Returns this BigInteger as an int value. If this is too big to be represented as an int, then this % (1 << 32) is returned. 
Tests whether this BigInteger is probably prime. If true is returned, then this is prime with a probability beyond 1 - 1/pow(2, certainty). If false is returned, then this is definitely composite. If the argument certainty <= 0, then this method returns true.
| certainty | tolerated primality uncertainty. | 
|---|
true, if this is probably prime, false otherwise. Returns this BigInteger as a long value. If this is too big to be represented as a long, then this % pow(2, 64) is returned. 
Returns the maximum of this BigInteger and value.
| value | value to be used to compute the maximum with this | 
|---|
| NullPointerException | if value == null | 
|---|
Returns the minimum of this BigInteger and value.
| value | value to be used to compute the minimum with this. | 
|---|
| NullPointerException | if value == null. | 
|---|
Returns a BigInteger whose value is this mod m. The modulus m must be positive. The result is guaranteed to be in the interval [0, m) (0 inclusive, m exclusive). The behavior of this function is not equivalent to the behavior of the % operator defined for the built-in int's.
| m | the modulus. | 
|---|
this mod m.| NullPointerException | if m == null. | 
|---|---|
| ArithmeticException | if m < 0. | 
Returns a BigInteger whose value is 1/this mod m. The modulus m must be positive. The result is guaranteed to be in the interval [0, m) (0 inclusive, m exclusive). If this is not relatively prime to m, then an exception is thrown.
| m | the modulus. | 
|---|
| NullPointerException | if m == null | 
|---|---|
| ArithmeticException | if m < 0 orifthisis not relatively prime tom | 
Returns a BigInteger whose value is pow(this, exponent) mod m. The modulus m must be positive. The result is guaranteed to be in the interval [0, m) (0 inclusive, m exclusive). If the exponent is negative, then pow(this.modInverse(m), -exponent) mod m is computed. The inverse of this only exists if this is relatively prime to m, otherwise an exception is thrown.
| exponent | the exponent. | 
|---|---|
| m | the modulus. | 
| NullPointerException | if m == nullorexponent == null. | 
|---|---|
| ArithmeticException | if m < 0or ifexponent<0and this is not relatively prime tom. | 
Returns a BigInteger whose value is this * value.
| NullPointerException | if value == null. | 
|---|
Returns the smallest integer x > this which is probably prime as a BigInteger instance. The probability that the returned BigInteger is prime is beyond 1 - 1/pow(2, 80).
this which is probably prime.| ArithmeticException | if this < 0. | 
|---|
Returns a BigInteger whose value is ~this. The result of this operation is -this-1. 
Implementation Note: Usage of this method is not recommended as the current implementation is not efficient.
Returns a BigInteger whose value is this | value. 
Implementation Note: Usage of this method is not recommended as the current implementation is not efficient.
| value | value to be or'ed with this. | 
|---|
| NullPointerException | if value == null. | 
|---|
Returns a BigInteger whose value is pow(this, exp).
| ArithmeticException | if exp < 0. | 
|---|
Returns a random positive BigInteger instance in the range [0, pow(2, bitLength)-1] which is probably prime. The probability that the returned BigInteger is prime is beyond 1 - 1/pow(2, 80). 
Implementation Note: Currently random is ignored.
| bitLength | length of the new BigIntegerin bits. | 
|---|
BigInteger instance.| IllegalArgumentException | if bitLength < 2. | 
|---|
Returns a BigInteger whose value is this % divisor. Regarding signs this methods has the same behavior as the % operator on ints: the sign of the remainder is the same as the sign of this.
| divisor | value by which thisis divided. | 
|---|
| NullPointerException | if divisor == null. | 
|---|---|
| ArithmeticException | if divisor == 0. | 
Returns a BigInteger which has the same binary representation as this but with the bit at position n set. The result is equivalent to this | pow(2, n). 
Implementation Note: Usage of this method is not recommended as the current implementation is not efficient.
| n | position where the bit in thishas to be set. | 
|---|
| ArithmeticException | if n < 0. | 
|---|
Returns a BigInteger whose value is this << n. The result is equivalent to this * pow(2, n) if n >= 0. The shift distance may be negative which means that this is shifted right. The result then corresponds to floor(this / pow(2, -n)). 
Implementation Note: Usage of this method on negative values is not recommended as the current implementation is not efficient.
| n | shift distance. | 
|---|
this << n if n >= 0; this >> (-n). otherwise Returns a BigInteger whose value is this >> n. For negative arguments, the result is also negative. The shift distance may be negative which means that this is shifted left. 
Implementation Note: Usage of this method on negative values is not recommended as the current implementation is not efficient.
| n | shift distance | 
|---|
this >> n if n >= 0; this << (-n) otherwise Returns the sign of this BigInteger.
-1 if this < 0, 0 if this == 0, 1 if this > 0. Returns a BigInteger whose value is this - value. 
Tests whether the bit at position n in this is set. The result is equivalent to this & pow(2, n) != 0. 
Implementation Note: Usage of this method is not recommended as the current implementation is not efficient.
| n | position where the bit in thishas to be inspected. | 
|---|
| ArithmeticException | if n < 0. | 
|---|
Returns the two's complement representation of this BigInteger in a byte array. 
Returns a string representation of this BigInteger in decimal form. 
Returns a string containing a string representation of this BigInteger with base radix. If radix < Character.MIN_RADIX or radix > Character.MAX_RADIX then a decimal representation is returned. The characters of the string representation are generated with method Character.forDigit.
| radix | base to be used for the string representation. | 
|---|
Returns a BigInteger whose value is equal to value. 
Returns a BigInteger whose value is this ^ value. 
Implementation Note: Usage of this method is not recommended as the current implementation is not efficient.
| value | value to be xor'ed with this | 
|---|
| NullPointerException | if value == null | 
|---|