# 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).
See Also:
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,
int radix)```

## Method Details

### abs

`public BigInteger abs()`

### add

`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.

java.math.BigInteger -- Arbitary precision integers Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2010 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.