- All Implemented Interfaces:
- Serializable,- Comparable<BigInteger>
Semantics of arithmetic operations exactly mimic those of Java's integer
 arithmetic operators, as defined in The Java Language Specification.
 For example, division by zero throws an ArithmeticException, and
 division of a negative by a positive yields a negative (or zero) remainder.
 
Semantics of shift operations extend those of Java's shift operators
 to allow for negative shift distances.  A right-shift with a negative
 shift distance results in a left shift, and vice-versa.  The unsigned
 right shift operator (>>>) is omitted since this operation
 only makes sense for a fixed sized word and not for a
 representation conceptually having an infinite number of leading
 virtual sign bits.
 
Semantics of bitwise logical operations exactly mimic those of Java's
 bitwise integer operators.  The binary operators (and,
 or, xor) implicitly perform sign extension on the shorter
 of the two operands prior to performing the operation.
 
Comparison operations perform signed integer comparisons, analogous to those performed by Java's relational and equality operators.
Modular arithmetic operations are provided to compute residues, perform
 exponentiation, and compute multiplicative inverses.  These methods always
 return a non-negative result, between 0 and (modulus - 1),
 inclusive.
 
Bit operations operate on a single bit of the two's-complement representation of their operand. If necessary, the operand is sign-extended so that it contains the designated bit. None of the single-bit operations can produce a BigInteger with a different sign from the BigInteger being operated on, as they affect only a single bit, and the arbitrarily large abstraction provided by this class ensures that conceptually there are infinitely many "virtual sign bits" preceding each BigInteger.
For the sake of brevity and clarity, pseudo-code is used throughout the
 descriptions of BigInteger methods.  The pseudo-code expression
 (i + j) is shorthand for "a BigInteger whose value is
 that of the BigInteger i plus that of the BigInteger j."
 The pseudo-code expression (i == j) is shorthand for
 "true if and only if the BigInteger i represents the same
 value as the BigInteger j."  Other pseudo-code expressions are
 interpreted similarly.
 
All methods and constructors in this class throw
 NullPointerException when passed
 a null object reference for any input parameter.
 BigInteger must support values in the range
 -2Integer.MAX_VALUE (exclusive) to
 +2Integer.MAX_VALUE (exclusive)
 and may support values outside of that range.
 An ArithmeticException is thrown when a BigInteger
 constructor or method would generate a value outside of the
 supported range.
 The range of probable prime values is limited and may be less than
 the full supported positive range of BigInteger.
 The range must be at least 1 to 2500000000.
- Implementation Note:
- In the reference implementation, BigInteger constructors and
 operations throw ArithmeticExceptionwhen the result is out of the supported range of -2Integer.MAX_VALUE(exclusive) to +2Integer.MAX_VALUE(exclusive).
- See Java Language Specification:
- 
4.2.2 Integer Operations
- Since:
- 1.1
- See Also:
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final BigIntegerThe BigInteger constant one.static final BigIntegerThe BigInteger constant ten.static final BigIntegerThe BigInteger constant two.static final BigIntegerThe BigInteger constant zero.
- 
Constructor SummaryConstructorsConstructorDescriptionBigInteger(byte[] val) Translates a byte array containing the two's-complement binary representation of a BigInteger into a BigInteger.BigInteger(byte[] val, int off, int len) Translates a byte sub-array containing the two's-complement binary representation of a BigInteger into a BigInteger.BigInteger(int signum, byte[] magnitude) Translates the sign-magnitude representation of a BigInteger into a BigInteger.BigInteger(int signum, byte[] magnitude, int off, int len) Translates the sign-magnitude representation of a BigInteger into a BigInteger.BigInteger(int bitLength, int certainty, Random rnd) Constructs a randomly generated positive BigInteger that is probably prime, with the specified bitLength.BigInteger(int numBits, Random rnd) Constructs a randomly generated BigInteger, uniformly distributed over the range 0 to (2numBits- 1), inclusive.BigInteger(String val) Translates the decimal String representation of a BigInteger into a BigInteger.BigInteger(String val, int radix) Translates the String representation of a BigInteger in the specified radix into a BigInteger.
- 
Method SummaryModifier and TypeMethodDescriptionabs()Returns a BigInteger whose value is the absolute value of this BigInteger.add(BigInteger val) Returns a BigInteger whose value is(this + val).and(BigInteger val) Returns a BigInteger whose value is(this & val).andNot(BigInteger val) Returns a BigInteger whose value is(this & ~val).intbitCount()Returns the number of bits in the two's complement representation of this BigInteger that differ from its sign bit.intReturns the number of bits in the minimal two's-complement representation of this BigInteger, excluding a sign bit.byteConverts thisBigIntegerto abyte, checking for lost information.clearBit(int n) Returns a BigInteger whose value is equivalent to this BigInteger with the designated bit cleared.intcompareTo(BigInteger val) Compares this BigInteger with the specified BigInteger.divide(BigInteger val) Returns a BigInteger whose value is(this / val).Returns an array of two BigIntegers containing(this / val)followed by(this % val).doubleConverts this BigInteger to adouble.booleanCompares this BigInteger with the specified Object for equality.flipBit(int n) Returns a BigInteger whose value is equivalent to this BigInteger with the designated bit flipped.floatConverts this BigInteger to afloat.gcd(BigInteger val) Returns a BigInteger whose value is the greatest common divisor ofabs(this)andabs(val).intReturns the index of the rightmost (lowest-order) one bit in this BigInteger (the number of zero bits to the right of the rightmost one bit).inthashCode()Returns the hash code for this BigInteger.intintValue()Converts this BigInteger to anint.intConverts thisBigIntegerto anint, checking for lost information.booleanisProbablePrime(int certainty) Returnstrueif this BigInteger is probably prime,falseif it's definitely composite.longConverts this BigInteger to along.longConverts thisBigIntegerto along, checking for lost information.max(BigInteger val) Returns the maximum of this BigInteger andval.min(BigInteger val) Returns the minimum of this BigInteger andval.mod(BigInteger m) Returns a BigInteger whose value is(this mod m).Returns a BigInteger whose value is(this-1mod m).modPow(BigInteger exponent, BigInteger m) Returns a BigInteger whose value is(thisexponent mod m).multiply(BigInteger val) Returns a BigInteger whose value is(this * val).negate()Returns a BigInteger whose value is(-this).Returns the first integer greater than thisBigIntegerthat is probably prime.not()Returns a BigInteger whose value is(~this).or(BigInteger val) Returns a BigInteger whose value is(this | val).pow(int exponent) Returns a BigInteger whose value is(thisexponent).static BigIntegerprobablePrime(int bitLength, Random rnd) Returns a positive BigInteger that is probably prime, with the specified bitLength.remainder(BigInteger val) Returns a BigInteger whose value is(this % val).setBit(int n) Returns a BigInteger whose value is equivalent to this BigInteger with the designated bit set.shiftLeft(int n) Returns a BigInteger whose value is(this << n).shiftRight(int n) Returns a BigInteger whose value is(this >> n).shortConverts thisBigIntegerto ashort, checking for lost information.intsignum()Returns the signum function of this BigInteger.sqrt()Returns the integer square root of this BigInteger.Returns an array of two BigIntegers containing the integer square rootsofthisand its remainderthis - s*s, respectively.subtract(BigInteger val) Returns a BigInteger whose value is(this - val).booleantestBit(int n) Returnstrueif and only if the designated bit is set.byte[]Returns a byte array containing the two's-complement representation of this BigInteger.toString()Returns the decimal String representation of this BigInteger.toString(int radix) Returns the String representation of this BigInteger in the given radix.static BigIntegervalueOf(long val) Returns a BigInteger whose value is equal to that of the specifiedlong.xor(BigInteger val) Returns a BigInteger whose value is(this ^ val).Methods declared in class java.lang.NumberbyteValue, shortValue
- 
Field Details- 
ZEROThe BigInteger constant zero.- Since:
- 1.2
 
- 
ONEThe BigInteger constant one.- Since:
- 1.2
 
- 
TWOThe BigInteger constant two.- Since:
- 9
 
- 
TENThe BigInteger constant ten.- Since:
- 1.5
 
 
- 
- 
Constructor Details- 
BigIntegerpublic BigInteger(byte[] val, int off, int len) Translates a byte sub-array containing the two's-complement binary representation of a BigInteger into a BigInteger. The sub-array is specified via an offset into the array and a length. The sub-array is assumed to be in big-endian byte-order: the most significant byte is the element at indexoff. Thevalarray is assumed to be unchanged for the duration of the constructor call. AnIndexOutOfBoundsExceptionis thrown if the length of the arrayvalis non-zero and eitheroffis negative,lenis negative, oroff+lenis greater than the length ofval.- Parameters:
- val- byte array containing a sub-array which is the big-endian two's-complement binary representation of a BigInteger.
- off- the start offset of the binary representation.
- len- the number of bytes to use.
- Throws:
- NumberFormatException-- valis zero bytes long.
- IndexOutOfBoundsException- if the provided array offset and length would cause an index into the byte array to be negative or greater than or equal to the array length.
- Since:
- 9
 
- 
BigIntegerpublic BigInteger(byte[] val) Translates a byte array containing the two's-complement binary representation of a BigInteger into a BigInteger. The input array is assumed to be in big-endian byte-order: the most significant byte is in the zeroth element. Thevalarray is assumed to be unchanged for the duration of the constructor call.- Parameters:
- val- big-endian two's-complement binary representation of a BigInteger.
- Throws:
- NumberFormatException-- valis zero bytes long.
 
- 
BigIntegerpublic BigInteger(int signum, byte[] magnitude, int off, int len) Translates the sign-magnitude representation of a BigInteger into a BigInteger. The sign is represented as an integer signum value: -1 for negative, 0 for zero, or 1 for positive. The magnitude is a sub-array of a byte array in big-endian byte-order: the most significant byte is the element at indexoff. A zero value of the lengthlenis permissible, and will result in a BigInteger value of 0, whether signum is -1, 0 or 1. Themagnitudearray is assumed to be unchanged for the duration of the constructor call. AnIndexOutOfBoundsExceptionis thrown if the length of the arraymagnitudeis non-zero and eitheroffis negative,lenis negative, oroff+lenis greater than the length ofmagnitude.- Parameters:
- signum- signum of the number (-1 for negative, 0 for zero, 1 for positive).
- magnitude- big-endian binary representation of the magnitude of the number.
- off- the start offset of the binary representation.
- len- the number of bytes to use.
- Throws:
- NumberFormatException-- signumis not one of the three legal values (-1, 0, and 1), or- signumis 0 and- magnitudecontains one or more non-zero bytes.
- IndexOutOfBoundsException- if the provided array offset and length would cause an index into the byte array to be negative or greater than or equal to the array length.
- Since:
- 9
 
- 
BigIntegerpublic BigInteger(int signum, byte[] magnitude) Translates the sign-magnitude representation of a BigInteger into a BigInteger. The sign is represented as an integer signum value: -1 for negative, 0 for zero, or 1 for positive. The magnitude is a byte array in big-endian byte-order: the most significant byte is the zeroth element. A zero-length magnitude array is permissible, and will result in a BigInteger value of 0, whether signum is -1, 0 or 1. Themagnitudearray is assumed to be unchanged for the duration of the constructor call.- Parameters:
- signum- signum of the number (-1 for negative, 0 for zero, 1 for positive).
- magnitude- big-endian binary representation of the magnitude of the number.
- Throws:
- NumberFormatException-- signumis not one of the three legal values (-1, 0, and 1), or- signumis 0 and- magnitudecontains one or more non-zero bytes.
 
- 
BigIntegerTranslates the String representation of a BigInteger in the specified radix into a BigInteger. The String representation consists of an optional minus or plus sign followed by a sequence of one or more digits in the specified radix. The character-to-digit mapping is provided byCharacter.digit. The String may not contain any extraneous characters (whitespace, for example).- Parameters:
- val- String representation of BigInteger.
- radix- radix to be used in interpreting- val.
- Throws:
- NumberFormatException-- valis not a valid representation of a BigInteger in the specified radix, or- radixis outside the range from- Character.MIN_RADIXto- Character.MAX_RADIX, inclusive.
 
- 
BigIntegerTranslates the decimal String representation of a BigInteger into a BigInteger. The String representation consists of an optional minus or plus sign followed by a sequence of one or more decimal digits. The character-to-digit mapping is provided byCharacter.digit. The String may not contain any extraneous characters (whitespace, for example).- Parameters:
- val- decimal String representation of BigInteger.
- Throws:
- NumberFormatException-- valis not a valid representation of a BigInteger.
 
- 
BigIntegerConstructs a randomly generated BigInteger, uniformly distributed over the range 0 to (2numBits- 1), inclusive. The uniformity of the distribution assumes that a fair source of random bits is provided inrnd. Note that this constructor always constructs a non-negative BigInteger.- Parameters:
- numBits- maximum bitLength of the new BigInteger.
- rnd- source of randomness to be used in computing the new BigInteger.
- Throws:
- IllegalArgumentException-- numBitsis negative.
- See Also:
 
- 
BigIntegerConstructs a randomly generated positive BigInteger that is probably prime, with the specified bitLength.- API Note:
- It is recommended that the probablePrimemethod be used in preference to this constructor unless there is a compelling need to specify a certainty.
- Parameters:
- bitLength- bitLength of the returned BigInteger.
- certainty- a measure of the uncertainty that the caller is willing to tolerate. The probability that the new BigInteger represents a prime number will exceed (1 - 1/2- certainty). The execution time of this constructor is proportional to the value of this parameter.
- rnd- source of random bits used to select candidates to be tested for primality.
- Throws:
- ArithmeticException-- bitLength < 2or- bitLengthis too large.
- See Also:
 
 
- 
- 
Method Details- 
probablePrimeReturns a positive BigInteger that is probably prime, with the specified bitLength. The probability that a BigInteger returned by this method is composite does not exceed 2-100.- Parameters:
- bitLength- bitLength of the returned BigInteger.
- rnd- source of random bits used to select candidates to be tested for primality.
- Returns:
- a BigInteger of bitLengthbits that is probably prime
- Throws:
- ArithmeticException-- bitLength < 2or- bitLengthis too large.
- Since:
- 1.4
- See Also:
 
- 
nextProbablePrimeReturns the first integer greater than thisBigIntegerthat is probably prime. The probability that the number returned by this method is composite does not exceed 2-100. This method will never skip over a prime when searching: if it returnsp, there is no primeqsuch thatthis < q < p.- Returns:
- the first integer greater than this BigIntegerthat is probably prime.
- Throws:
- ArithmeticException-- this < 0or- thisis too large.
- Since:
- 1.5
 
- 
valueOfReturns a BigInteger whose value is equal to that of the specifiedlong.- API Note:
- This static factory method is provided in preference
 to a (long) constructor because it allows for reuse of frequently used BigIntegers.
- Parameters:
- val- value of the BigInteger to return.
- Returns:
- a BigInteger with the specified value.
 
- 
addReturns a BigInteger whose value is(this + val).- Parameters:
- val- value to be added to this BigInteger.
- Returns:
- this + val
 
- 
subtractReturns a BigInteger whose value is(this - val).- Parameters:
- val- value to be subtracted from this BigInteger.
- Returns:
- this - val
 
- 
multiplyReturns a BigInteger whose value is(this * val).- Implementation Note:
- An implementation may offer better algorithmic
 performance when val == this.
- Parameters:
- val- value to be multiplied by this BigInteger.
- Returns:
- this * val
 
- 
divideReturns a BigInteger whose value is(this / val).- Parameters:
- val- value by which this BigInteger is to be divided.
- Returns:
- this / val
- Throws:
- ArithmeticException- if- valis zero.
 
- 
divideAndRemainderReturns an array of two BigIntegers containing(this / val)followed by(this % val).- Parameters:
- val- value by which this BigInteger is to be divided, and the remainder computed.
- Returns:
- an array of two BigIntegers: the quotient (this / val)is the initial element, and the remainder(this % val)is the final element.
- Throws:
- ArithmeticException- if- valis zero.
 
- 
remainderReturns a BigInteger whose value is(this % val).- Parameters:
- val- value by which this BigInteger is to be divided, and the remainder computed.
- Returns:
- this % val
- Throws:
- ArithmeticException- if- valis zero.
 
- 
powReturns a BigInteger whose value is(thisexponent). Note thatexponentis an integer rather than a BigInteger.- Parameters:
- exponent- exponent to which this BigInteger is to be raised.
- Returns:
- thisexponent
- Throws:
- ArithmeticException-- exponentis negative. (This would cause the operation to yield a non-integer value.)
 
- 
sqrtReturns the integer square root of this BigInteger. The integer square root of the corresponding mathematical integernis the largest mathematical integerssuch thats*s <= n. It is equal to the value offloor(sqrt(n)), wheresqrt(n)denotes the real square root ofntreated as a real. Note that the integer square root will be less than the real square root if the latter is not representable as an integral value.- Returns:
- the integer square root of this
- Throws:
- ArithmeticException- if- thisis negative. (The square root of a negative integer- valis- (i * sqrt(-val))where i is the imaginary unit and is equal to- sqrt(-1).)
- Since:
- 9
 
- 
sqrtAndRemainderReturns an array of two BigIntegers containing the integer square rootsofthisand its remainderthis - s*s, respectively.- Returns:
- an array of two BigIntegers with the integer square root at offset 0 and the remainder at offset 1
- Throws:
- ArithmeticException- if- thisis negative. (The square root of a negative integer- valis- (i * sqrt(-val))where i is the imaginary unit and is equal to- sqrt(-1).)
- Since:
- 9
- See Also:
 
- 
gcdReturns a BigInteger whose value is the greatest common divisor ofabs(this)andabs(val). Returns 0 ifthis == 0 && val == 0.- Parameters:
- val- value with which the GCD is to be computed.
- Returns:
- GCD(abs(this), abs(val))
 
- 
absReturns a BigInteger whose value is the absolute value of this BigInteger.- Returns:
- abs(this)
 
- 
negateReturns a BigInteger whose value is(-this).- Returns:
- -this
 
- 
signumpublic int signum()Returns the signum function of this BigInteger.- Returns:
- -1, 0 or 1 as the value of this BigInteger is negative, zero or positive.
 
- 
modReturns a BigInteger whose value is(this mod m). This method differs fromremainderin that it always returns a non-negative BigInteger.- Parameters:
- m- the modulus.
- Returns:
- this mod m
- Throws:
- ArithmeticException-- m≤ 0
- See Also:
 
- 
modPowReturns a BigInteger whose value is(thisexponent mod m). (Unlikepow, this method permits negative exponents.)- Parameters:
- exponent- the exponent.
- m- the modulus.
- Returns:
- thisexponent mod m
- Throws:
- ArithmeticException-- m≤ 0 or the exponent is negative and this BigInteger is not relatively prime to- m.
- See Also:
 
- 
modInverseReturns a BigInteger whose value is(this-1mod m).- Parameters:
- m- the modulus.
- Returns:
- this-1- mod m.
- Throws:
- ArithmeticException-- m≤ 0, or this BigInteger has no multiplicative inverse mod m (that is, this BigInteger is not relatively prime to m).
 
- 
shiftLeftReturns a BigInteger whose value is(this << n). The shift distance,n, may be negative, in which case this method performs a right shift. (Computesfloor(this * 2n).)- Parameters:
- n- shift distance, in bits.
- Returns:
- this << n
- See Also:
 
- 
shiftRightReturns a BigInteger whose value is(this >> n). Sign extension is performed. The shift distance,n, may be negative, in which case this method performs a left shift. (Computesfloor(this / 2n).)- Parameters:
- n- shift distance, in bits.
- Returns:
- this >> n
- See Also:
 
- 
andReturns a BigInteger whose value is(this & val). (This method returns a negative BigInteger if and only if this and val are both negative.)- Parameters:
- val- value to be AND'ed with this BigInteger.
- Returns:
- this & val
 
- 
orReturns a BigInteger whose value is(this | val). (This method returns a negative BigInteger if and only if either this or val is negative.)- Parameters:
- val- value to be OR'ed with this BigInteger.
- Returns:
- this | val
 
- 
xorReturns a BigInteger whose value is(this ^ val). (This method returns a negative BigInteger if and only if exactly one of this and val are negative.)- Parameters:
- val- value to be XOR'ed with this BigInteger.
- Returns:
- this ^ val
 
- 
notReturns a BigInteger whose value is(~this). (This method returns a negative value if and only if this BigInteger is non-negative.)- Returns:
- ~this
 
- 
andNotReturns a BigInteger whose value is(this & ~val). This method, which is equivalent toand(val.not()), is provided as a convenience for masking operations. (This method returns a negative BigInteger if and only ifthisis negative andvalis positive.)- Parameters:
- val- value to be complemented and AND'ed with this BigInteger.
- Returns:
- this & ~val
 
- 
testBitpublic boolean testBit(int n) Returnstrueif and only if the designated bit is set. (Computes((this & (1<<n)) != 0).)- Parameters:
- n- index of bit to test.
- Returns:
- trueif and only if the designated bit is set.
- Throws:
- ArithmeticException-- nis negative.
 
- 
setBitReturns a BigInteger whose value is equivalent to this BigInteger with the designated bit set. (Computes(this | (1<<n)).)- Parameters:
- n- index of bit to set.
- Returns:
- this | (1<<n)
- Throws:
- ArithmeticException-- nis negative.
 
- 
clearBitReturns a BigInteger whose value is equivalent to this BigInteger with the designated bit cleared. (Computes(this & ~(1<<n)).)- Parameters:
- n- index of bit to clear.
- Returns:
- this & ~(1<<n)
- Throws:
- ArithmeticException-- nis negative.
 
- 
flipBitReturns a BigInteger whose value is equivalent to this BigInteger with the designated bit flipped. (Computes(this ^ (1<<n)).)- Parameters:
- n- index of bit to flip.
- Returns:
- this ^ (1<<n)
- Throws:
- ArithmeticException-- nis negative.
 
- 
getLowestSetBitpublic int getLowestSetBit()Returns the index of the rightmost (lowest-order) one bit in this BigInteger (the number of zero bits to the right of the rightmost one bit). Returns -1 if this BigInteger contains no one bits. (Computes(this == 0? -1 : log2(this & -this)).)- Returns:
- index of the rightmost one bit in this BigInteger.
 
- 
bitLengthpublic int bitLength()Returns the number of bits in the minimal two's-complement representation of this BigInteger, excluding a sign bit. For positive BigIntegers, this is equivalent to the number of bits in the ordinary binary representation. For zero this method returns0. (Computes(ceil(log2(this < 0 ? -this : this+1))).)- Returns:
- number of bits in the minimal two's-complement representation of this BigInteger, excluding a sign bit.
 
- 
bitCountpublic int bitCount()Returns the number of bits in the two's complement representation of this BigInteger that differ from its sign bit. This method is useful when implementing bit-vector style sets atop BigIntegers.- Returns:
- number of bits in the two's complement representation of this BigInteger that differ from its sign bit.
 
- 
isProbablePrimepublic boolean isProbablePrime(int certainty) Returnstrueif this BigInteger is probably prime,falseif it's definitely composite. Ifcertaintyis ≤ 0,trueis returned.- Parameters:
- certainty- a measure of the uncertainty that the caller is willing to tolerate: if the call returns- truethe probability that this BigInteger is prime exceeds (1 - 1/2- certainty). The execution time of this method is proportional to the value of this parameter.
- Returns:
- trueif this BigInteger is probably prime,- falseif it's definitely composite.
 
- 
compareToCompares this BigInteger with the specified BigInteger. This method is provided in preference to individual methods for each of the six boolean comparison operators (<, ==, >, >=, !=, <=). The suggested idiom for performing these comparisons is:(x.compareTo(y)<op>0), where <op> is one of the six comparison operators.- Specified by:
- compareToin interface- Comparable<BigInteger>
- Parameters:
- val- BigInteger to which this BigInteger is to be compared.
- Returns:
- -1, 0 or 1 as this BigInteger is numerically less than, equal
         to, or greater than val.
 
- 
equalsCompares this BigInteger with the specified Object for equality.
- 
minReturns the minimum of this BigInteger andval.- Parameters:
- val- value with which the minimum is to be computed.
- Returns:
- the BigInteger whose value is the lesser of this BigInteger and
         val. If they are equal, either may be returned.
 
- 
maxReturns the maximum of this BigInteger andval.- Parameters:
- val- value with which the maximum is to be computed.
- Returns:
- the BigInteger whose value is the greater of this and
         val. If they are equal, either may be returned.
 
- 
hashCodepublic int hashCode()Returns the hash code for this BigInteger.
- 
toStringReturns the String representation of this BigInteger in the given radix. If the radix is outside the range fromCharacter.MIN_RADIXtoCharacter.MAX_RADIXinclusive, it will default to 10 (as is the case forInteger.toString). The digit-to-character mapping provided byCharacter.forDigitis used, and a minus sign is prepended if appropriate. (This representation is compatible with the(String, int)constructor.)- Parameters:
- radix- radix of the String representation.
- Returns:
- String representation of this BigInteger in the given radix.
- See Also:
 
- 
toStringReturns the decimal String representation of this BigInteger. The digit-to-character mapping provided byCharacter.forDigitis used, and a minus sign is prepended if appropriate. (This representation is compatible with the(String)constructor, and allows for String concatenation with Java's + operator.)
- 
toByteArraypublic byte[] toByteArray()Returns a byte array containing the two's-complement representation of this BigInteger. The byte array will be in big-endian byte-order: the most significant byte is in the zeroth element. The array will contain the minimum number of bytes required to represent this BigInteger, including at least one sign bit, which is(ceil((this.bitLength() + 1)/8)). (This representation is compatible with the(byte[])constructor.)- Returns:
- a byte array containing the two's-complement representation of this BigInteger.
- See Also:
 
- 
intValuepublic int intValue()Converts this BigInteger to anint. This conversion is analogous to a narrowing primitive conversion fromlongtointas defined in The Java Language Specification: if this BigInteger is too big to fit in anint, only the low-order 32 bits are returned. Note that this conversion can lose information about the overall magnitude of the BigInteger value as well as return a result with the opposite sign.- Specified by:
- intValuein class- Number
- Returns:
- this BigInteger converted to an int.
- See Java Language Specification:
- 
5.1.3 Narrowing Primitive Conversion
- See Also:
 
- 
longValuepublic long longValue()Converts this BigInteger to along. This conversion is analogous to a narrowing primitive conversion fromlongtointas defined in The Java Language Specification: if this BigInteger is too big to fit in along, only the low-order 64 bits are returned. Note that this conversion can lose information about the overall magnitude of the BigInteger value as well as return a result with the opposite sign.- Specified by:
- longValuein class- Number
- Returns:
- this BigInteger converted to a long.
- See Java Language Specification:
- 
5.1.3 Narrowing Primitive Conversion
- See Also:
 
- 
floatValuepublic float floatValue()Converts this BigInteger to afloat. This conversion is similar to the narrowing primitive conversion fromdoubletofloatas defined in The Java Language Specification: if this BigInteger has too great a magnitude to represent as afloat, it will be converted toFloat.NEGATIVE_INFINITYorFloat.POSITIVE_INFINITYas appropriate. Note that even when the return value is finite, this conversion can lose information about the precision of the BigInteger value.- Specified by:
- floatValuein class- Number
- Returns:
- this BigInteger converted to a float.
- See Java Language Specification:
- 
5.1.3 Narrowing Primitive Conversion
 
- 
doubleValuepublic double doubleValue()Converts this BigInteger to adouble. This conversion is similar to the narrowing primitive conversion fromdoubletofloatas defined in The Java Language Specification: if this BigInteger has too great a magnitude to represent as adouble, it will be converted toDouble.NEGATIVE_INFINITYorDouble.POSITIVE_INFINITYas appropriate. Note that even when the return value is finite, this conversion can lose information about the precision of the BigInteger value.- Specified by:
- doubleValuein class- Number
- Returns:
- this BigInteger converted to a double.
- See Java Language Specification:
- 
5.1.3 Narrowing Primitive Conversion
 
- 
longValueExactpublic long longValueExact()Converts thisBigIntegerto along, checking for lost information. If the value of thisBigIntegeris out of the range of thelongtype, then anArithmeticExceptionis thrown.- Returns:
- this BigIntegerconverted to along.
- Throws:
- ArithmeticException- if the value of- thiswill not exactly fit in a- long.
- Since:
- 1.8
- See Also:
 
- 
intValueExactpublic int intValueExact()Converts thisBigIntegerto anint, checking for lost information. If the value of thisBigIntegeris out of the range of theinttype, then anArithmeticExceptionis thrown.- Returns:
- this BigIntegerconverted to anint.
- Throws:
- ArithmeticException- if the value of- thiswill not exactly fit in an- int.
- Since:
- 1.8
- See Also:
 
- 
shortValueExactpublic short shortValueExact()Converts thisBigIntegerto ashort, checking for lost information. If the value of thisBigIntegeris out of the range of theshorttype, then anArithmeticExceptionis thrown.- Returns:
- this BigIntegerconverted to ashort.
- Throws:
- ArithmeticException- if the value of- thiswill not exactly fit in a- short.
- Since:
- 1.8
- See Also:
 
- 
byteValueExactpublic byte byteValueExact()Converts thisBigIntegerto abyte, checking for lost information. If the value of thisBigIntegeris out of the range of thebytetype, then anArithmeticExceptionis thrown.- Returns:
- this BigIntegerconverted to abyte.
- Throws:
- ArithmeticException- if the value of- thiswill not exactly fit in a- byte.
- Since:
- 1.8
- See Also:
 
 
-