java.math.BigInteger
java.lang.Number
None
None
New as of JDK 1.1
The BigInteger class represents an arbitrary-precision integer value. You should use this class if a long is not big enough for your purposes. The number in a BigInteger is represented by a sign value and a magnitude, which is an arbitrarily large array of bytes. A BigInteger cannot overflow.
Most of the methods in BigInteger perform mathematical operations or make comparisons with other BigInteger objects. BigInteger also defines some methods for handling modular arithmetic and determining primality that are needed for cryptographic purposes.
public class java.math.BigInteger extends java.lang.Number { // Constructors public BigInteger(byte[] val); public BigInteger(int signum, byte[] magnitude); public BigInteger(String val); public BigInteger(String val, int radix); public BigInteger(int numBits, Random rndSrc); public BigInteger(int bitLength, int certainty, Random rnd); // Class Methods public static BigInteger valueOf(long val); // Instance Methods public BigInteger abs(); public BigInteger add(BigInteger val); public BigInteger and(BigInteger val); public BigInteger andNot(BigInteger val); public int bitCount(); public int bitLength(); public BigInteger clearBit(int n); public int compareTo(BigInteger val); public BigInteger divide(BigInteger val); public BigInteger[] divideAndRemainder(BigInteger val); public double doubleValue(); public boolean equals(Object x); public BigInteger flipBit(int n); public float floatValue(); public BigInteger gcd(BigInteger val); public int getLowestSetBit(); public int hashCode(); public int intValue(); public boolean isProbablePrime(int certainty); public long longValue(); public BigInteger max(BigInteger val); public BigInteger min(BigInteger val); public BigInteger mod(BigInteger m); public BigInteger modInverse(BigInteger m); public BigInteger modPow(BigInteger exponent, BigInteger m); public BigInteger multiply(BigInteger val); public BigInteger negate(); public BigInteger not(); public BigInteger or(BigInteger val); public BigInteger pow(int exponent); public BigInteger remainder(BigInteger val); public BigInteger setBit(int n); public BigInteger shiftLeft(int n); public BigInteger shiftRight(int n); public int signum(); public BigInteger subtract(BigInteger val); public boolean testBit(int n); public byte[] toByteArray(); public String toString(); public String toString(int radix); public BigInteger xor(BigInteger val); }
The initial value.
If the array does not contain any bytes.
This constructor creates a BigInteger with the given initial value. The value is expressed as a two's complement signed integer, with the most significant byte in the first position (val[0]) of the array (big-endian). The most significant bit of the most significant byte is the sign bit.
public BigInteger(int signum, byte[] magnitude) throws NumberFormatException
The sign of the value: -1 indicates negative, 0 indicates zero, and 1 indicates positive.
The initial magnitude of the value.
If signum is invalid or if signum is 0 but magnitude is not 0.
This constructor creates a BigInteger with the given initial value and sign. The magnitude is expressed as a big-endian byte array.
The initial value.
If the string cannot be parsed into a valid BigInteger.
This constructor creates a BigInteger with the initial value specified by the String. The string can contain an optional minus sign followed by zero or more decimal digits. The mapping from characters to digits is provided by the Character.digit() method.
public BigInteger(String val, int radix) throws NumberFormatException
The initial value.
The radix to use to parse the given string.
If the string cannot be parsed, or if the radix is not in the allowed range (Character.MIN_RADIX through Character.MAX_RADIX).
This constructor creates a BigInteger with the initial value specified by the String using the given radix. The string can contain an optional minus sign followed by zero or more digits in the specified radix. The mapping from characters to digits is provided by the Character.digit() method.
public BigInteger(int numBits, Random rndSrc) throws IllegalArgumentException
The maximum number of bits in the returned number.
The source of the random bits.
If numBits is less than zero.
This constructor creates a random BigInteger in the range 0 to 2^numBits -1.
The maximum number of bits in the returned number.
The certainty that the returned value is a prime number.
The source of the random bits.
If numBits is less than 2.
This constructor creates a random BigInteger in the range 0 to 2^numBits-1 that is probably a prime number. The probability that the returned number is prime is greater than 1-.5^certainty. In other words, the higher the value of certainty, the more likely the BigInteger is to be prime, and also the longer it takes for the constructor to create the BigInteger.
The initial value.
A BigInteger that represents the given value.
This method creates a BigInteger from the given long value.
A BigInteger that contains the absolute value of this number.
This method returns the absolute value of this BigInteger. If this BigInteger is nonnegative, it is returned. Otherwise, a new BigInteger that contains the absolute value of this BigInteger is returned.
The number to be added.
A new BigInteger that contains the sum of this number and the given value.
If any kind of arithmetic error occurs.
This method returns the sum of this BigInteger and the given BigInteger as a new BigInteger.
The number to be ANDed.
A new BigInteger that contains the bitwise AND of this number and the given value.
This method returns the bitwise AND of this BigInteger and the supplied BigInteger as a new BigInteger.
The number to be combined with this BigInteger.
A new BigInteger that contains the bitwise AND of this number and the bitwise negation of the given value.
This method returns the bitwise AND of this BigInteger and the bitwise negation of the given BigInteger as a new BigInteger. Calling this method is equivalent to calling and(val.not()).
The number of bits that differ from this BigInteger's sign bit.
This method returns the number of bits in the two's complement representation of this BigInteger that differ from the sign bit of this BigInteger.
The number of bits needed to represent this number, excluding a sign bit.
This method returns the minimum number of bits needed to represent this number, not counting a sign bit.
The bit to clear.
A new BigInteger that contains the value of this BigInteger with the given bit cleared.
If n is less than 0.
This method returns a new BigInteger that is equal to this BigInteger, except that the given bit is cleared, or set to zero.
The value to be compared.
-1 if this number is less than val, 0 if this number is equal to val, or 1 if this number is greater than val.
This method compares this BigInteger to the given BigInteger and returns a value that indicates the result of the comparison. This method can be used to implement all six of the standard boolean comparison operators: ==, !=, <=, <, >=, and >.
The divisor.
A new BigInteger that contains the result (quotient) of dividing this number by the given value.
If val is zero.
This method returns the quotient that results from dividing this BigInteger by the given BigInteger as a new BigInteger. Any fractional remainder is discarded.
public BigInteger[] divideAndRemainder(BigInteger val) throws ArithmeticException
The divisor.
An array of BigInteger objects that contains the quotient and remainder (in that order) that result from dividing this number by the given value.
If val is zero.
This method returns the quotient and remainder that results from dividing this BigInteger by the given BigInteger as an array of new BigInteger objects. The first element of the array is equal to divide(val); the second element is equal to remainder(val).
The value of this BigInteger as a double.
Number.doubleValue()
This method returns the value of this BigInteger as a double. If the value exceeds the limits of a double, Double.POSITIVE_INFINITY or Double.NEGATIVE_INFINITY is returned.
The object to be compared with this object.
true if the objects are equal; false if they are not.
Object.equals()
This method returns true if x is an instance of BigInteger, and it represents the same value as this BigInteger.
The bit to toggle.
A new BigInteger that contains the value of this BigInteger with the given bit toggled.
If n is less than 0.
This method returns a new BigInteger that is equal to this BigInteger, except that the given bit is toggled. In other words, if the given bit is 0, it is set to one, or if it is 1, it is set to zero.
The value of this BigInteger as a float.
Number.floatValue()
This method returns the value of this BigInteger as a float. If the value exceeds the limits of a float, Float.POSITIVE_INFINITY or Float.NEGATIVE_INFINITY is returned.
The number to be compared.
A new BigInteger that contains the greatest common denominator of this number and the given number.
This method calculates the greatest common denominator of the absolute value of this BigInteger and the absolute value of the given BigInteger, and returns it as a new BigInteger. If both values are 0, the method returns a BigInteger that contains the value 0.
The index of the lowest-order bit with a value of 1, or -1 if there are no bits that are 1.
This method returns the index of the lowest-order, or rightmost, bit with a value of 1.
A hashcode for this object.
Object.hashCode()
This method returns a hashcode for this BigInteger.
The value of this BigInteger as an int.
Number.intValue()
This method returns the value of this BigInteger as an int. If the value exceeds the limits of an int, the excessive high-order bits are discarded.
The "certainty" that this number is prime, where a higher value indicates more certainty.
true if this number is probably prime; false if it is definitely not prime.
This method returns true if this number has a probability of being prime that is greater than 1-.5^certainty. If the number is definitely not prime, false is returned.
The value of this BigInteger as a long.
Number.longValue()
This method returns the value of this BigInteger as a long. If the value exceeds the limits of a long, the excessive high-order bits are discarded.
The number to be compared.
The BigInteger that represents the greater of this number and the given value.
This method returns the greater of this BigInteger and the given BigInteger.
The number to be compared.
The BigInteger that represents the lesser of this number and the given value.
This method returns the lesser of this BigInteger and the given BigInteger.
The number to use.
A new BigInteger that contains the modulus of this number and the given number.
If m is less than or equal to zero.
This method returns a new BigInteger that contains the value of this BigInteger mod m.
public BigInteger modInverse(BigInteger m) throws ArithmeticException
The number to use.
A new BigInteger that contains the multiplicative inverse of the modulus of this number and the given number.
If m is less than or equal to zero, or if the result cannot be calculated.
This method returns a new BigInteger that contains the multiplicative inverse of the value of this BigInteger mod m.
The exponent.
The number to use.
A new BigInteger that contains the modulus of this number raised to the given power and the given number.
If m is less than or equal to zero.
This method returns a new BigInteger that contains the value of this BigInteger raised to the given power mod m.
The number to be multiplied.
A new BigInteger that contains the product of this number and the given number.
This method multiplies this BigInteger by the given BigInteger and returns the product as a new BigInteger.
A new BigInteger that contains the negative of this number.
This method returns a new BigInteger that is identical to this BigInteger except that its sign is reversed.
A new BigInteger that contains the bitwise negation of this number.
This method returns a new BigInteger that is calculated by inverting every bit of this BigInteger.
The value to be ORed.
A new BigInteger that contains the bitwise OR of this number and the given value.
This method returns the bitwise OR of this BigInteger and the given BigInteger as a new BigInteger.
The exponent.
A new BigInteger that contains the result of raising this number to the given power.
If exponent is less than zero.
This method raises this BigInteger to the given power and returns the result as a new BigInteger.
public BigInteger remainder(BigInteger val) throws ArithmeticException
The divisor.
A new BigInteger that contains the remainder that results from dividing this number by the given value.
If val is zero.
This method returns the remainder that results from dividing this BigInteger by the given BigInteger as a new BigInteger.
The bit to set.
A new BigInteger that contains the value of this BigInteger with the given bit set.
If n is less than zero.
This method returns a new BigInteger that is equal to this BigInteger, except that the given bit is set to 1.
The number of bits to shift.
A new BigInteger that contains the result of shifting the bits of this number left by the given number of bits.
This method returns a new BigInteger that contains the value of this BigInteger left-shifted by the given number of bits.
The number of bits to shift.
A new BigInteger that contains the result of shifting the bits of this number right by the given number of bits with sign extension.
This method returns a new BigInteger that contains the value of this BigInteger right-shifted by the given number of bits with sign extension.
-1 is this number is negative, 0 if this number is zero, or 1 if this number is positive.
This method returns a value that indicates the sign of this BigInteger.
The number to be subtracted.
A new BigDecimal that contains the result of subtracting the given number from this number.
This method subtracts the given BigInteger from this BigInteger and returns the result as a new BigInteger.
The bit to test.
true if the specified bit is 1; false if the specified bit is 0.
If n is less than zero.
This method returns true if the specified bit in this BigInteger is 1. Otherwise the method returns false.
An array of bytes that represents this object.
This method returns an array of bytes that contains the two's complement representation of this BigInteger. The most significant byte is in the first position (val[0]) of the array. The array can be used with the BigInteger(byte[]) constructor to reconstruct the number.
A string representation of this object in decimal form.
Object.toString()
This method returns a string representation of this BigInteger in decimal form. A minus sign represents the sign if necessary. The mapping from digits to characters is provided by the Character.forDigit() method.
The radix to use.
A string representation of this object in the given radix.
Object.toString()
This method returns a string representation of this BigInteger for the given radix. A minus sign is used to represent the sign if necessary. The mapping from digits to characters is provided by the Character.forDigit() method.
The value to be XORed.
A new BigInteger that contains the bitwise XOR of this number and the given value.
This method returns the bitwise XOR of this BigInteger and the given BigInteger as a new BigInteger.
Method |
Inherited From |
Method |
Inherited From |
---|---|---|---|
byteValue() |
Number |
clone() |
Object |
getClass() |
Object |
finalize() |
Object |
notify() |
Object |
notifyAll() |
Object |
shortValue() |
Number |
wait() |
Object |
wait(long) |
Object |
wait(long, int) |
Object |
ArithmeticException, BigDecimal, Character, Double, Float, IllegalArgumentException, Integer, Long, Number, NumberFormatException
This HTML Help has been published using the chm2web software. |