# Class BigInteger

• `java.lang.Object`
• `java.lang.Number`
• `java.math.BigInteger`
Implemented Interfaces:
Comparable<T>, Serializable

`public class BigInteger`
`extends Number`
`implements Comparable<T>`

Written using on-line Java Platform 1.2 API Specification, as well as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998) and "Applied Cryptography, Second Edition" by Bruce Schneier (Wiley, 1996). Based primarily on IntNum.java BitOps.java by Per Bothner (per@bothner.com) (found in Kawa 1.6.62).
Serialized Form

## Field Summary

`static BigInteger`
`ONE`
The constant one as a BigInteger.
`static BigInteger`
`TEN`
The constant ten as a BigInteger.
`static BigInteger`
`ZERO`
The constant zero as a BigInteger.

## Constructor Summary

`BigInteger(byte[] val)`
`BigInteger(int signum, byte[] magnitude)`
`BigInteger(int bitLength, int certainty, Random rnd)`
`BigInteger(int numBits, Random rnd)`
`BigInteger(String val)`
`BigInteger(String s, int radix)`

## Method Summary

` BigInteger`
`abs()`
` BigInteger`
`add(BigInteger val)`
` BigInteger`
`and(BigInteger y)`
Return the logical (bit-wise) "and" of two BigIntegers.
` BigInteger`
`andNot(BigInteger val)`
` int`
`bitCount()`
Count one bits in a BigInteger.
` int`
`bitLength()`
Calculates ceiling(log2(this <320 ?
` BigInteger`
`clearBit(int n)`
` int`
`compareTo(BigInteger val)`
` BigInteger`
`divide(BigInteger val)`
` BigInteger[]`
`divideAndRemainder(BigInteger val)`
` double`
`doubleValue()`
` boolean`
`equals(Object obj)`
` BigInteger`
`flipBit(int n)`
` float`
`floatValue()`
` BigInteger`
`gcd(BigInteger y)`
` int`
`getLowestSetBit()`
` int`
`hashCode()`
` int`
`intValue()`
` boolean`
`isProbablePrime(int certainty)`
Returns `true` if this BigInteger is probably prime, `false` if it's definitely composite.
` long`
`longValue()`
` BigInteger`
`max(BigInteger val)`
` BigInteger`
`min(BigInteger val)`
` BigInteger`
`mod(BigInteger m)`
` BigInteger`
`modInverse(BigInteger y)`
` BigInteger`
`modPow(BigInteger exponent, BigInteger m)`
` BigInteger`
`multiply(BigInteger y)`
` BigInteger`
`negate()`
` BigInteger`
`not()`
Return the logical (bit-wise) negation of a BigInteger.
` BigInteger`
`or(BigInteger y)`
Return the logical (bit-wise) "(inclusive) or" of two BigIntegers.
` BigInteger`
`pow(int exponent)`
Calculate the integral power of a BigInteger.
`static BigInteger`
`probablePrime(int bitLength, Random rnd)`
Return a BigInteger that is bitLength bits long with a probability <322^-100 of being composite.
` BigInteger`
`remainder(BigInteger val)`
` BigInteger`
`setBit(int n)`
` BigInteger`
`shiftLeft(int n)`
` BigInteger`
`shiftRight(int n)`
` int`
`signum()`
` BigInteger`
`subtract(BigInteger val)`
` boolean`
`testBit(int n)`
` byte[]`
`toByteArray()`
` String`
`toString()`
` String`
`toString(int radix)`
`static BigInteger`
`valueOf(long val)`
Return a (possibly-shared) BigInteger with a given long value.
` BigInteger`
`xor(BigInteger y)`
Return the logical (bit-wise) "exclusive or" of two BigIntegers.

### Methods inherited from class java.lang.Number

`byteValue`, `doubleValue`, `floatValue`, `intValue`, `longValue`, `shortValue`

### Methods inherited from class java.lang.Object

`clone`, `equals`, `extends Object> getClass`, `finalize`, `hashCode`, `notify`, `notifyAll`, `toString`, `wait`, `wait`, `wait`

## Field Details

### ONE

`public static final BigInteger ONE`
The constant one as a BigInteger.
Since:
1.2

### TEN

`public static final BigInteger TEN`
The constant ten as a BigInteger.
Since:
1.5

### ZERO

`public static final BigInteger ZERO`
The constant zero as a BigInteger.
Since:
1.2

## Constructor Details

### BigInteger

`public BigInteger(byte[] val)`

### BigInteger

```public BigInteger(int signum,
byte[] magnitude)```

### BigInteger

```public BigInteger(int bitLength,
int certainty,
Random rnd)```

### BigInteger

```public BigInteger(int numBits,
Random rnd)```

### BigInteger

`public BigInteger(String val)`

### BigInteger

```public BigInteger(String s,

## Method Details

### abs

`public BigInteger abs()`

`public BigInteger add(BigInteger val)`

### and

`public BigInteger and(BigInteger y)`
Return the logical (bit-wise) "and" of two BigIntegers.

### andNot

`public BigInteger andNot(BigInteger val)`

### bitCount

`public int bitCount()`
Count one bits in a BigInteger. If argument is negative, count zero bits instead.

### bitLength

`public int bitLength()`
Calculates ceiling(log2(this <320 ? -this : this+1)) See Common Lisp: the Language, 2nd ed, p. 361.

### clearBit

`public BigInteger clearBit(int n)`

### compareTo

`public int compareTo(BigInteger val)`
Since:
1.2

### divide

`public BigInteger divide(BigInteger val)`

### divideAndRemainder

`public BigInteger[] divideAndRemainder(BigInteger val)`

### doubleValue

`public double doubleValue()`
Overrides:
doubleValue in interface Number

### equals

`public boolean equals(Object obj)`
Overrides:
equals in interface Object

### flipBit

`public BigInteger flipBit(int n)`

### floatValue

`public float floatValue()`
Overrides:
floatValue in interface Number

### gcd

`public BigInteger gcd(BigInteger y)`

### getLowestSetBit

`public int getLowestSetBit()`

### hashCode

`public int hashCode()`
Overrides:
hashCode in interface Object

### intValue

`public int intValue()`
Overrides:
intValue in interface Number

### isProbablePrime

`public boolean isProbablePrime(int certainty)`
Returns `true` if this BigInteger is probably prime, `false` if it's definitely composite. If `certainty` is `<= 0`, `true` is returned.
Parameters:
`certainty` - a measure of the uncertainty that the caller is willing to tolerate: if the call returns `true` the probability that this BigInteger is prime exceeds `(1 - 1/2certainty)`. The execution time of this method is proportional to the value of this parameter.
Returns:
`true` if this BigInteger is probably prime, `false` if it's definitely composite.

### longValue

`public long longValue()`
Overrides:
longValue in interface Number

### max

`public BigInteger max(BigInteger val)`

### min

`public BigInteger min(BigInteger val)`

### mod

`public BigInteger mod(BigInteger m)`

### modInverse

`public BigInteger modInverse(BigInteger y)`

### modPow

```public BigInteger modPow(BigInteger exponent,
BigInteger m)```

### multiply

`public BigInteger multiply(BigInteger y)`

### negate

`public BigInteger negate()`

### not

`public BigInteger not()`
Return the logical (bit-wise) negation of a BigInteger.

### or

`public BigInteger or(BigInteger y)`
Return the logical (bit-wise) "(inclusive) or" of two BigIntegers.

### pow

`public BigInteger pow(int exponent)`
Calculate the integral power of a BigInteger.
Parameters:
`exponent` - the exponent (must be non-negative)

### probablePrime

```public static BigInteger probablePrime(int bitLength,
Random rnd)```
Return a BigInteger that is bitLength bits long with a probability <322^-100 of being composite.
Parameters:
`bitLength` - length in bits of resulting number
`rnd` - random number generator to use
Throws:
`ArithmeticException` - if bitLength <322
Since:
1.4

### remainder

`public BigInteger remainder(BigInteger val)`

### setBit

`public BigInteger setBit(int n)`

### shiftLeft

`public BigInteger shiftLeft(int n)`

### shiftRight

`public BigInteger shiftRight(int n)`

### signum

`public int signum()`

### subtract

`public BigInteger subtract(BigInteger val)`

### testBit

`public boolean testBit(int n)`

### toByteArray

`public byte[] toByteArray()`

### toString

`public String toString()`
Overrides:
toString in interface Object

### toString

`public String toString(int radix)`

### valueOf

`public static BigInteger valueOf(long val)`
Return a (possibly-shared) BigInteger with a given long value.

### xor

`public BigInteger xor(BigInteger y)`
Return the logical (bit-wise) "exclusive or" of two BigIntegers.