Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Fields](https://developer.android.com/reference/java/math/BigInteger#lfields) \| [Ctors](https://developer.android.com/reference/java/math/BigInteger#pubctors) \| [Methods](https://developer.android.com/reference/java/math/BigInteger#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/java/math/BigInteger#inhmethods)

# BigInteger

` public class BigInteger `   
` ` ` extends https://developer.android.com/reference/java/lang/Number ` ` implements https://developer.android.com/reference/java/lang/Comparable<https://developer.android.com/reference/java/math/BigInteger> `

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) |||
| ↳ | [java.lang.Number](https://developer.android.com/reference/java/lang/Number) ||
|   | ↳ | java.math.BigInteger |

<br />

*** ** * ** ***

Immutable arbitrary-precision integers. All operations behave as if BigIntegers were represented in two's-complement notation (like Java's primitive integer types). BigInteger provides analogues to all of Java's primitive integer operators, and all relevant methods from java.lang.Math. Additionally, BigInteger provides operations for modular arithmetic, GCD calculation, primality testing, prime generation, bit manipulation, and a few other miscellaneous operations.

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 -2^`Integer.MAX_VALUE`^ (exclusive) to +2^`Integer.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 2^500000000^.
**See also:**

- `https://developer.android.com/reference/java/math/BigDecimal`

## Summary

| ### Fields ||
|---|---|
| ` public static final https://developer.android.com/reference/java/math/BigInteger` | `https://developer.android.com/reference/java/math/BigInteger#ONE` The BigInteger constant one. |
| ` public static final https://developer.android.com/reference/java/math/BigInteger` | `https://developer.android.com/reference/java/math/BigInteger#TEN` The BigInteger constant ten. |
| ` public static final https://developer.android.com/reference/java/math/BigInteger` | `https://developer.android.com/reference/java/math/BigInteger#TWO` The BigInteger constant two. |
| ` public static final https://developer.android.com/reference/java/math/BigInteger` | `https://developer.android.com/reference/java/math/BigInteger#ZERO` The BigInteger constant zero. |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/java/math/BigInteger#BigInteger(byte[])(byte[] val) ` Translates a byte array containing the two's-complement binary representation of a BigInteger into a BigInteger. |
| ` https://developer.android.com/reference/java/math/BigInteger#BigInteger(byte[],%20int,%20int)(byte[] val, int off, int len) ` Translates a byte sub-array containing the two's-complement binary representation of a BigInteger into a BigInteger. |
| ` https://developer.android.com/reference/java/math/BigInteger#BigInteger(int,%20byte[])(int signum, byte[] magnitude) ` Translates the sign-magnitude representation of a BigInteger into a BigInteger. |
| ` https://developer.android.com/reference/java/math/BigInteger#BigInteger(int,%20byte[],%20int,%20int)(int signum, byte[] magnitude, int off, int len) ` Translates the sign-magnitude representation of a BigInteger into a BigInteger. |
| ` https://developer.android.com/reference/java/math/BigInteger#BigInteger(int,%20int,%20java.util.Random)(int bitLength, int certainty, https://developer.android.com/reference/java/util/Random rnd) ` Constructs a randomly generated positive BigInteger that is probably prime, with the specified bitLength. |
| ` https://developer.android.com/reference/java/math/BigInteger#BigInteger(int,%20java.util.Random)(int numBits, https://developer.android.com/reference/java/util/Random rnd) ` Constructs a randomly generated BigInteger, uniformly distributed over the range 0 to (2^`numBits`^ - 1), inclusive. |
| ` https://developer.android.com/reference/java/math/BigInteger#BigInteger(java.lang.String)(https://developer.android.com/reference/java/lang/String val) ` Translates the decimal String representation of a BigInteger into a BigInteger. |
| ` https://developer.android.com/reference/java/math/BigInteger#BigInteger(java.lang.String,%20int)(https://developer.android.com/reference/java/lang/String val, int radix) ` Translates the String representation of a BigInteger in the specified radix into a BigInteger. |

| ### Public methods ||
|---|---|
| ` https://developer.android.com/reference/java/math/BigInteger` | ` https://developer.android.com/reference/java/math/BigInteger#abs()() ` Returns a BigInteger whose value is the absolute value of this BigInteger. |
| ` https://developer.android.com/reference/java/math/BigInteger` | ` https://developer.android.com/reference/java/math/BigInteger#add(java.math.BigInteger)(https://developer.android.com/reference/java/math/BigInteger val) ` Returns a BigInteger whose value is `(this + val)`. |
| ` https://developer.android.com/reference/java/math/BigInteger` | ` https://developer.android.com/reference/java/math/BigInteger#and(java.math.BigInteger)(https://developer.android.com/reference/java/math/BigInteger val) ` Returns a BigInteger whose value is `(this & val)`. |
| ` https://developer.android.com/reference/java/math/BigInteger` | ` https://developer.android.com/reference/java/math/BigInteger#andNot(java.math.BigInteger)(https://developer.android.com/reference/java/math/BigInteger val) ` Returns a BigInteger whose value is `(this & ~val)`. |
| ` int` | ` https://developer.android.com/reference/java/math/BigInteger#bitCount()() ` Returns the number of bits in the two's complement representation of this BigInteger that differ from its sign bit. |
| ` int` | ` https://developer.android.com/reference/java/math/BigInteger#bitLength()() ` Returns the number of bits in the minimal two's-complement representation of this BigInteger, *excluding* a sign bit. |
| ` byte` | ` https://developer.android.com/reference/java/math/BigInteger#byteValueExact()() ` Converts this `BigInteger` to a `byte`, checking for lost information. |
| ` https://developer.android.com/reference/java/math/BigInteger` | ` https://developer.android.com/reference/java/math/BigInteger#clearBit(int)(int n) ` Returns a BigInteger whose value is equivalent to this BigInteger with the designated bit cleared. |
| ` int` | ` https://developer.android.com/reference/java/math/BigInteger#compareTo(java.math.BigInteger)(https://developer.android.com/reference/java/math/BigInteger val) ` Compares this BigInteger with the specified BigInteger. |
| ` https://developer.android.com/reference/java/math/BigInteger` | ` https://developer.android.com/reference/java/math/BigInteger#divide(java.math.BigInteger)(https://developer.android.com/reference/java/math/BigInteger val) ` Returns a BigInteger whose value is `(this / val)`. |
| ` https://developer.android.com/reference/java/math/BigInteger` | ` https://developer.android.com/reference/java/math/BigInteger#divideAndRemainder(java.math.BigInteger)(https://developer.android.com/reference/java/math/BigInteger val) ` Returns an array of two BigIntegers containing `(this / val)` followed by `(this % val)`. |
| ` double` | ` https://developer.android.com/reference/java/math/BigInteger#doubleValue()() ` Converts this BigInteger to a `double`. |
| ` boolean` | ` https://developer.android.com/reference/java/math/BigInteger#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object x) ` Compares this BigInteger with the specified Object for equality. |
| ` https://developer.android.com/reference/java/math/BigInteger` | ` https://developer.android.com/reference/java/math/BigInteger#flipBit(int)(int n) ` Returns a BigInteger whose value is equivalent to this BigInteger with the designated bit flipped. |
| ` float` | ` https://developer.android.com/reference/java/math/BigInteger#floatValue()() ` Converts this BigInteger to a `float`. |
| ` https://developer.android.com/reference/java/math/BigInteger` | ` https://developer.android.com/reference/java/math/BigInteger#gcd(java.math.BigInteger)(https://developer.android.com/reference/java/math/BigInteger val) ` Returns a BigInteger whose value is the greatest common divisor of `abs(this)` and `abs(val)`. |
| ` int` | ` https://developer.android.com/reference/java/math/BigInteger#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). |
| ` int` | ` https://developer.android.com/reference/java/math/BigInteger#hashCode()() ` Returns the hash code for this BigInteger. |
| ` int` | ` https://developer.android.com/reference/java/math/BigInteger#intValue()() ` Converts this BigInteger to an `int`. |
| ` int` | ` https://developer.android.com/reference/java/math/BigInteger#intValueExact()() ` Converts this `BigInteger` to an `int`, checking for lost information. |
| ` boolean` | ` https://developer.android.com/reference/java/math/BigInteger#isProbablePrime(int)(int certainty) ` Returns `true` if this BigInteger is probably prime, `false` if it's definitely composite. |
| ` long` | ` https://developer.android.com/reference/java/math/BigInteger#longValue()() ` Converts this BigInteger to a `long`. |
| ` long` | ` https://developer.android.com/reference/java/math/BigInteger#longValueExact()() ` Converts this `BigInteger` to a `long`, checking for lost information. |
| ` https://developer.android.com/reference/java/math/BigInteger` | ` https://developer.android.com/reference/java/math/BigInteger#max(java.math.BigInteger)(https://developer.android.com/reference/java/math/BigInteger val) ` Returns the maximum of this BigInteger and `val`. |
| ` https://developer.android.com/reference/java/math/BigInteger` | ` https://developer.android.com/reference/java/math/BigInteger#min(java.math.BigInteger)(https://developer.android.com/reference/java/math/BigInteger val) ` Returns the minimum of this BigInteger and `val`. |
| ` https://developer.android.com/reference/java/math/BigInteger` | ` https://developer.android.com/reference/java/math/BigInteger#mod(java.math.BigInteger)(https://developer.android.com/reference/java/math/BigInteger m) ` Returns a BigInteger whose value is `(this mod m`). |
| ` https://developer.android.com/reference/java/math/BigInteger` | ` https://developer.android.com/reference/java/math/BigInteger#modInverse(java.math.BigInteger)(https://developer.android.com/reference/java/math/BigInteger m) ` Returns a BigInteger whose value is `(this`^-1^ `mod m)`. |
| ` https://developer.android.com/reference/java/math/BigInteger` | ` https://developer.android.com/reference/java/math/BigInteger#modPow(java.math.BigInteger,%20java.math.BigInteger)(https://developer.android.com/reference/java/math/BigInteger exponent, https://developer.android.com/reference/java/math/BigInteger m) ` Returns a BigInteger whose value is `(thisexponent mod m)`. |
| ` https://developer.android.com/reference/java/math/BigInteger` | ` https://developer.android.com/reference/java/math/BigInteger#multiply(java.math.BigInteger)(https://developer.android.com/reference/java/math/BigInteger val) ` Returns a BigInteger whose value is `(this * val)`. |
| ` https://developer.android.com/reference/java/math/BigInteger` | ` https://developer.android.com/reference/java/math/BigInteger#negate()() ` Returns a BigInteger whose value is `(-this)`. |
| ` https://developer.android.com/reference/java/math/BigInteger` | ` https://developer.android.com/reference/java/math/BigInteger#nextProbablePrime()() ` Returns the first integer greater than this `BigInteger` that is probably prime. |
| ` https://developer.android.com/reference/java/math/BigInteger` | ` https://developer.android.com/reference/java/math/BigInteger#not()() ` Returns a BigInteger whose value is `(~this)`. |
| ` https://developer.android.com/reference/java/math/BigInteger` | ` https://developer.android.com/reference/java/math/BigInteger#or(java.math.BigInteger)(https://developer.android.com/reference/java/math/BigInteger val) ` Returns a BigInteger whose value is `(this | val)`. |
| ` https://developer.android.com/reference/java/math/BigInteger` | ` https://developer.android.com/reference/java/math/BigInteger#pow(int)(int exponent) ` Returns a BigInteger whose value is `(thisexponent)`. |
| ` static https://developer.android.com/reference/java/math/BigInteger` | ` https://developer.android.com/reference/java/math/BigInteger#probablePrime(int,%20java.util.Random)(int bitLength, https://developer.android.com/reference/java/util/Random rnd) ` Returns a positive BigInteger that is probably prime, with the specified bitLength. |
| ` https://developer.android.com/reference/java/math/BigInteger` | ` https://developer.android.com/reference/java/math/BigInteger#remainder(java.math.BigInteger)(https://developer.android.com/reference/java/math/BigInteger val) ` Returns a BigInteger whose value is `(this % val)`. |
| ` https://developer.android.com/reference/java/math/BigInteger` | ` https://developer.android.com/reference/java/math/BigInteger#setBit(int)(int n) ` Returns a BigInteger whose value is equivalent to this BigInteger with the designated bit set. |
| ` https://developer.android.com/reference/java/math/BigInteger` | ` https://developer.android.com/reference/java/math/BigInteger#shiftLeft(int)(int n) ` Returns a BigInteger whose value is `(this << n)`. |
| ` https://developer.android.com/reference/java/math/BigInteger` | ` https://developer.android.com/reference/java/math/BigInteger#shiftRight(int)(int n) ` Returns a BigInteger whose value is `(this >> n)`. |
| ` short` | ` https://developer.android.com/reference/java/math/BigInteger#shortValueExact()() ` Converts this `BigInteger` to a `short`, checking for lost information. |
| ` int` | ` https://developer.android.com/reference/java/math/BigInteger#signum()() ` Returns the signum function of this BigInteger. |
| ` https://developer.android.com/reference/java/math/BigInteger` | ` https://developer.android.com/reference/java/math/BigInteger#sqrt()() ` Returns the integer square root of this BigInteger. |
| ` https://developer.android.com/reference/java/math/BigInteger` | ` https://developer.android.com/reference/java/math/BigInteger#sqrtAndRemainder()() ` Returns an array of two BigIntegers containing the integer square root `s` of `this` and its remainder `this - s*s`, respectively. |
| ` https://developer.android.com/reference/java/math/BigInteger` | ` https://developer.android.com/reference/java/math/BigInteger#subtract(java.math.BigInteger)(https://developer.android.com/reference/java/math/BigInteger val) ` Returns a BigInteger whose value is `(this - val)`. |
| ` boolean` | ` https://developer.android.com/reference/java/math/BigInteger#testBit(int)(int n) ` Returns `true` if and only if the designated bit is set. |
| ` byte[]` | ` https://developer.android.com/reference/java/math/BigInteger#toByteArray()() ` Returns a byte array containing the two's-complement representation of this BigInteger. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/math/BigInteger#toString()() ` Returns the decimal String representation of this BigInteger. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/math/BigInteger#toString(int)(int radix) ` Returns the String representation of this BigInteger in the given radix. |
| ` static https://developer.android.com/reference/java/math/BigInteger` | ` https://developer.android.com/reference/java/math/BigInteger#valueOf(long)(long val) ` Returns a BigInteger whose value is equal to that of the specified `long`. |
| ` https://developer.android.com/reference/java/math/BigInteger` | ` https://developer.android.com/reference/java/math/BigInteger#xor(java.math.BigInteger)(https://developer.android.com/reference/java/math/BigInteger val) ` Returns a BigInteger whose value is `(this ^ val)`. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Number ` ` byte` ` https://developer.android.com/reference/java/lang/Number#byteValue()() `

Returns the value of the specified number as a `byte`.
` abstract double` ` https://developer.android.com/reference/java/lang/Number#doubleValue()() `

Returns the value of the specified number as a `double`.
` abstract float` ` https://developer.android.com/reference/java/lang/Number#floatValue()() `

Returns the value of the specified number as a `float`.
` abstract int` ` https://developer.android.com/reference/java/lang/Number#intValue()() `

Returns the value of the specified number as an `int`.
` abstract long` ` https://developer.android.com/reference/java/lang/Number#longValue()() `

Returns the value of the specified number as a `long`.
` short` ` https://developer.android.com/reference/java/lang/Number#shortValue()() `

Returns the value of the specified number as a `short`.
From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.
From interface ` https://developer.android.com/reference/java/lang/Comparable ` ` abstract int` ` https://developer.android.com/reference/java/lang/Comparable#compareTo(T)(https://developer.android.com/reference/java/math/BigInteger o) `

Compares this object with the specified object for order.

## Fields

### ONE

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final BigInteger ONE
```

The BigInteger constant one.

<br />

### TEN

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final BigInteger TEN
```

The BigInteger constant ten.

<br />

### TWO

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final BigInteger TWO
```

The BigInteger constant two.

<br />

### ZERO

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final BigInteger ZERO
```

The BigInteger constant zero.

<br />

## Public constructors

### BigInteger

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public 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. The `val` array is assumed to be unchanged for the duration of the constructor call.

<br />

| Parameters ||
|---|---|
| `val` | `byte`: big-endian two's-complement binary representation of a BigInteger. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/NumberFormatException` | `val` is zero bytes long. |

### BigInteger

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public 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 index `off`. The `val` array is assumed to be unchanged for the duration of the constructor call. An `IndexOutOfBoundsException` is thrown if the length of the array `val` is non-zero and either `off` is negative, `len` is negative, or `off+len` is greater than the length of `val`.

<br />

| Parameters ||
|---|---|
| `val` | `byte`: byte array containing a sub-array which is the big-endian two's-complement binary representation of a BigInteger. <br /> |
| `off` | `int`: the start offset of the binary representation. <br /> |
| `len` | `int`: the number of bytes to use. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/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. |
| `https://developer.android.com/reference/java/lang/NumberFormatException` | `val` is zero bytes long. |

### BigInteger

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public 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. The `magnitude` array is assumed to be unchanged for the duration of the constructor call.

<br />

| Parameters ||
|---|---|
| `signum` | `int`: signum of the number (-1 for negative, 0 for zero, 1 for positive). <br /> |
| `magnitude` | `byte`: big-endian binary representation of the magnitude of the number. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/NumberFormatException` | `signum` is not one of the three legal values (-1, 0, and 1), or `signum` is 0 and `magnitude` contains one or more non-zero bytes. |

### BigInteger

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public 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 index `off`. A zero value of the length `len` is permissible, and will result in a BigInteger value of 0, whether signum is -1, 0 or 1. The `magnitude` array is assumed to be unchanged for the duration of the constructor call. An `IndexOutOfBoundsException` is thrown if the length of the array `magnitude` is non-zero and either `off` is negative, `len` is negative, or `off+len` is greater than the length of `magnitude`.

<br />

| Parameters ||
|---|---|
| `signum` | `int`: signum of the number (-1 for negative, 0 for zero, 1 for positive). <br /> |
| `magnitude` | `byte`: big-endian binary representation of the magnitude of the number. <br /> |
| `off` | `int`: the start offset of the binary representation. <br /> |
| `len` | `int`: the number of bytes to use. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/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. |
| `https://developer.android.com/reference/java/lang/NumberFormatException` | `signum` is not one of the three legal values (-1, 0, and 1), or `signum` is 0 and `magnitude` contains one or more non-zero bytes. |

### BigInteger

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

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

Constructs a randomly generated positive BigInteger that is probably prime, with the specified bitLength.

<br />

##### API Note:

- It is recommended that the `https://developer.android.com/reference/java/math/BigInteger#probablePrime(int,%20java.util.Random)` method be used in preference to this constructor unless there is a compelling need to specify a certainty.

| Parameters ||
|---|---|
| `bitLength` | `int`: bitLength of the returned BigInteger. <br /> |
| `certainty` | `int`: 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. <br /> |
| `rnd` | `Random`: source of random bits used to select candidates to be tested for primality. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/ArithmeticException` | `bitLength < 2` or `bitLength` is too large. |

**See also:**

- `https://developer.android.com/reference/java/math/BigInteger#bitLength()`

### BigInteger

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

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

Constructs a randomly generated BigInteger, uniformly distributed over the range 0 to (2^`numBits`^ - 1), inclusive. The uniformity of the distribution assumes that a fair source of random bits is provided in `rnd`. Note that this constructor always constructs a non-negative BigInteger.

<br />

| Parameters ||
|---|---|
| `numBits` | `int`: maximum bitLength of the new BigInteger. <br /> |
| `rnd` | `Random`: source of randomness to be used in computing the new BigInteger. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | `numBits` is negative. |

**See also:**

- `https://developer.android.com/reference/java/math/BigInteger#bitLength()`

### BigInteger

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public BigInteger (String val)
```

Translates 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 by `https://developer.android.com/reference/java/lang/Character#digit(char,%20int)`. The String may not contain any extraneous characters (whitespace, for example).

<br />

| Parameters ||
|---|---|
| `val` | `String`: decimal String representation of BigInteger. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/NumberFormatException` | `val` is not a valid representation of a BigInteger. |

### BigInteger

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public BigInteger (String val, 
                int radix)
```

Translates 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 by `https://developer.android.com/reference/java/lang/Character#digit(char,%20int)`. The String may not contain any extraneous characters (whitespace, for example).

<br />

| Parameters ||
|---|---|
| `val` | `String`: String representation of BigInteger. <br /> |
| `radix` | `int`: radix to be used in interpreting `val`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/NumberFormatException` | `val` is not a valid representation of a BigInteger in the specified radix, or `radix` is outside the range from `https://developer.android.com/reference/java/lang/Character#MIN_RADIX` to `https://developer.android.com/reference/java/lang/Character#MAX_RADIX`, inclusive. |

## Public methods

### abs

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public BigInteger abs ()
```

Returns a BigInteger whose value is the absolute value of this BigInteger.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/math/BigInteger` | `abs(this)` <br /> |

### add

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public BigInteger add (BigInteger val)
```

Returns a BigInteger whose value is `(this + val)`.

<br />

| Parameters ||
|---|---|
| `val` | `BigInteger`: value to be added to this BigInteger. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/math/BigInteger` | `this + val` <br /> |

### and

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public BigInteger and (BigInteger val)
```

Returns a BigInteger whose value is `(this & val)`. (This method returns a negative BigInteger if and only if this and val are both negative.)

<br />

| Parameters ||
|---|---|
| `val` | `BigInteger`: value to be AND'ed with this BigInteger. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/math/BigInteger` | `this & val` <br /> |

### andNot

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public BigInteger andNot (BigInteger val)
```

Returns a BigInteger whose value is `(this & ~val)`. This method, which is equivalent to `and(val.not())`, is provided as a convenience for masking operations. (This method returns a negative BigInteger if and only if `this` is negative and `val` is positive.)

<br />

| Parameters ||
|---|---|
| `val` | `BigInteger`: value to be complemented and AND'ed with this BigInteger. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/math/BigInteger` | `this & ~val` <br /> |

### bitCount

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

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

<br />

| Returns ||
|---|---|
| `int` | number of bits in the two's complement representation of this BigInteger that differ from its sign bit. <br /> |

### bitLength

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public 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 returns `0`. (Computes `(ceil(log2(this < 0 ? -this : this+1)))`.)

<br />

| Returns ||
|---|---|
| `int` | number of bits in the minimal two's-complement representation of this BigInteger, *excluding* a sign bit. <br /> |

### byteValueExact

Added in [API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public byte byteValueExact ()
```

Converts this `BigInteger` to a `byte`, checking for lost information. If the value of this `BigInteger` is out of the range of the `byte` type, then an `ArithmeticException` is thrown.

<br />

| Returns ||
|---|---|
| `byte` | this `BigInteger` converted to a `byte`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/ArithmeticException` | if the value of `this` will not exactly fit in a `byte`. |

**See also:**

- `https://developer.android.com/reference/java/lang/Number#byteValue()`

### clearBit

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public BigInteger clearBit (int n)
```

Returns a BigInteger whose value is equivalent to this BigInteger with the designated bit cleared. (Computes `(this & ~(1<<n))`.)

<br />

| Parameters ||
|---|---|
| `n` | `int`: index of bit to clear. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/math/BigInteger` | `this & ~(1<<n)` <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/ArithmeticException` | `n` is negative. |

### compareTo

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int compareTo (BigInteger val)
```

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

<br />

| Parameters ||
|---|---|
| `val` | `BigInteger`: BigInteger to which this BigInteger is to be compared. <br /> |

| Returns ||
|---|---|
| `int` | -1, 0 or 1 as this BigInteger is numerically less than, equal to, or greater than `val`. <br /> |

### divide

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public BigInteger divide (BigInteger val)
```

Returns a BigInteger whose value is `(this / val)`.

<br />

| Parameters ||
|---|---|
| `val` | `BigInteger`: value by which this BigInteger is to be divided. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/math/BigInteger` | `this / val` <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/ArithmeticException` | if `val` is zero. |

### divideAndRemainder

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public BigInteger[] divideAndRemainder (BigInteger val)
```

Returns an array of two BigIntegers containing `(this / val)` followed by `(this % val)`.

<br />

| Parameters ||
|---|---|
| `val` | `BigInteger`: value by which this BigInteger is to be divided, and the remainder computed. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/math/BigInteger` | an array of two BigIntegers: the quotient `(this / val)` is the initial element, and the remainder `(this % val)` is the final element. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/ArithmeticException` | if `val` is zero. |

### doubleValue

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public double doubleValue ()
```

Converts this BigInteger to a `double`. This conversion is similar to the *narrowing primitive conversion* from `double` to `float` as defined in The Java Language Specification: if this BigInteger has too great a magnitude to represent as a `double`, it will be converted to `https://developer.android.com/reference/java/lang/Double#NEGATIVE_INFINITY` or `https://developer.android.com/reference/java/lang/Double#POSITIVE_INFINITY` as appropriate. Note that even when the return value is finite, this conversion can lose information about the precision of the BigInteger value.

<br />

| Returns ||
|---|---|
| `double` | this BigInteger converted to a `double`. <br /> |

### equals

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean equals (Object x)
```

Compares this BigInteger with the specified Object for equality.

<br />

| Parameters ||
|---|---|
| `x` | `Object`: Object to which this BigInteger is to be compared. <br /> |

| Returns ||
|---|---|
| `boolean` | `true` if and only if the specified Object is a BigInteger whose value is numerically equal to this BigInteger. <br /> |

### flipBit

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public BigInteger flipBit (int n)
```

Returns a BigInteger whose value is equivalent to this BigInteger with the designated bit flipped. (Computes `(this ^ (1<<n))`.)

<br />

| Parameters ||
|---|---|
| `n` | `int`: index of bit to flip. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/math/BigInteger` | `this ^ (1<<n)` <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/ArithmeticException` | `n` is negative. |

### floatValue

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public float floatValue ()
```

Converts this BigInteger to a `float`. This conversion is similar to the *narrowing primitive conversion* from `double` to `float` as defined in The Java Language Specification: if this BigInteger has too great a magnitude to represent as a `float`, it will be converted to `https://developer.android.com/reference/java/lang/Float#NEGATIVE_INFINITY` or `https://developer.android.com/reference/java/lang/Float#POSITIVE_INFINITY` as appropriate. Note that even when the return value is finite, this conversion can lose information about the precision of the BigInteger value.

<br />

| Returns ||
|---|---|
| `float` | this BigInteger converted to a `float`. <br /> |

### gcd

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public BigInteger gcd (BigInteger val)
```

Returns a BigInteger whose value is the greatest common divisor of `abs(this)` and `abs(val)`. Returns 0 if `this == 0 && val == 0`.

<br />

| Parameters ||
|---|---|
| `val` | `BigInteger`: value with which the GCD is to be computed. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/math/BigInteger` | `GCD(abs(this), abs(val))` <br /> |

### getLowestSetBit

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

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

<br />

| Returns ||
|---|---|
| `int` | index of the rightmost one bit in this BigInteger. <br /> |

### hashCode

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int hashCode ()
```

Returns the hash code for this BigInteger.

<br />

| Returns ||
|---|---|
| `int` | hash code for this BigInteger. <br /> |

### intValue

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int intValue ()
```

Converts this BigInteger to an `int`. This conversion is analogous to a *narrowing primitive conversion* from `long` to `int` as defined in The Java Language Specification: if this BigInteger is too big to fit in an `int`, 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.

<br />

| Returns ||
|---|---|
| `int` | this BigInteger converted to an `int`. <br /> |

**See also:**

- `https://developer.android.com/reference/java/math/BigInteger#intValueExact()`

### intValueExact

Added in [API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int intValueExact ()
```

Converts this `BigInteger` to an `int`, checking for lost information. If the value of this `BigInteger` is out of the range of the `int` type, then an `ArithmeticException` is thrown.

<br />

| Returns ||
|---|---|
| `int` | this `BigInteger` converted to an `int`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/ArithmeticException` | if the value of `this` will not exactly fit in an `int`. |

**See also:**

- `https://developer.android.com/reference/java/math/BigInteger#intValue()`

### isProbablePrime

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

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

<br />

| Parameters ||
|---|---|
| `certainty` | `int`: 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/2^`certainty`^). The execution time of this method is proportional to the value of this parameter. <br /> |

| Returns ||
|---|---|
| `boolean` | `true` if this BigInteger is probably prime, `false` if it's definitely composite. <br /> |

### longValue

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public long longValue ()
```

Converts this BigInteger to a `long`. This conversion is analogous to a *narrowing primitive conversion* from `long` to `int` as defined in The Java Language Specification: if this BigInteger is too big to fit in a `long`, 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.

<br />

| Returns ||
|---|---|
| `long` | this BigInteger converted to a `long`. <br /> |

**See also:**

- `https://developer.android.com/reference/java/math/BigInteger#longValueExact()`

### longValueExact

Added in [API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public long longValueExact ()
```

Converts this `BigInteger` to a `long`, checking for lost information. If the value of this `BigInteger` is out of the range of the `long` type, then an `ArithmeticException` is thrown.

<br />

| Returns ||
|---|---|
| `long` | this `BigInteger` converted to a `long`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/ArithmeticException` | if the value of `this` will not exactly fit in a `long`. |

**See also:**

- `https://developer.android.com/reference/java/math/BigInteger#longValue()`

### max

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public BigInteger max (BigInteger val)
```

Returns the maximum of this BigInteger and `val`.

<br />

| Parameters ||
|---|---|
| `val` | `BigInteger`: value with which the maximum is to be computed. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/math/BigInteger` | the BigInteger whose value is the greater of this and `val`. If they are equal, either may be returned. <br /> |

### min

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public BigInteger min (BigInteger val)
```

Returns the minimum of this BigInteger and `val`.

<br />

| Parameters ||
|---|---|
| `val` | `BigInteger`: value with which the minimum is to be computed. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/math/BigInteger` | the BigInteger whose value is the lesser of this BigInteger and `val`. If they are equal, either may be returned. <br /> |

### mod

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public BigInteger mod (BigInteger m)
```

Returns a BigInteger whose value is `(this mod m`). This method differs from `remainder` in that it always returns a *non-negative* BigInteger.

<br />

| Parameters ||
|---|---|
| `m` | `BigInteger`: the modulus. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/math/BigInteger` | `this mod m` <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/ArithmeticException` | `m` ≤ 0 |

**See also:**

- `https://developer.android.com/reference/java/math/BigInteger#remainder(java.math.BigInteger)`

### modInverse

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public BigInteger modInverse (BigInteger m)
```

Returns a BigInteger whose value is `(this`^-1^ `mod m)`.

<br />

| Parameters ||
|---|---|
| `m` | `BigInteger`: the modulus. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/math/BigInteger` | `this`^-1^ `mod m`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/ArithmeticException` | `m` ≤ 0, or this BigInteger has no multiplicative inverse mod m (that is, this BigInteger is not *relatively prime* to m). |

### modPow

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

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

Returns a BigInteger whose value is `(thisexponent mod m)`. (Unlike `pow`, this method permits negative exponents.)

<br />

| Parameters ||
|---|---|
| `exponent` | `BigInteger`: the exponent. <br /> |
| `m` | `BigInteger`: the modulus. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/math/BigInteger` | `thisexponent mod m` <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/ArithmeticException` | `m` ≤ 0 or the exponent is negative and this BigInteger is not *relatively prime* to `m`. |

**See also:**

- `https://developer.android.com/reference/java/math/BigInteger#modInverse(java.math.BigInteger)`

### multiply

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public BigInteger multiply (BigInteger val)
```

Returns a BigInteger whose value is `(this * val)`.

<br />

##### Implementation Note:

- An implementation may offer better algorithmic performance when `val == this`.

| Parameters ||
|---|---|
| `val` | `BigInteger`: value to be multiplied by this BigInteger. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/math/BigInteger` | `this * val` <br /> |

### negate

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public BigInteger negate ()
```

Returns a BigInteger whose value is `(-this)`.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/math/BigInteger` | `-this` <br /> |

### nextProbablePrime

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public BigInteger nextProbablePrime ()
```

Returns the first integer greater than this `BigInteger` that 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 returns `p`, there is no prime `q` such that `this < q < p`.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/math/BigInteger` | the first integer greater than this `BigInteger` that is probably prime. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/ArithmeticException` | `this < 0` or `this` is too large. |

### not

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public BigInteger not ()
```

Returns a BigInteger whose value is `(~this)`. (This method returns a negative value if and only if this BigInteger is non-negative.)

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/math/BigInteger` | `~this` <br /> |

### or

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public BigInteger or (BigInteger val)
```

Returns a BigInteger whose value is `(this | val)`. (This method returns a negative BigInteger if and only if either this or val is negative.)

<br />

| Parameters ||
|---|---|
| `val` | `BigInteger`: value to be OR'ed with this BigInteger. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/math/BigInteger` | `this | val` <br /> |

### pow

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public BigInteger pow (int exponent)
```

Returns a BigInteger whose value is `(thisexponent)`. Note that `exponent` is an integer rather than a BigInteger.

<br />

| Parameters ||
|---|---|
| `exponent` | `int`: exponent to which this BigInteger is to be raised. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/math/BigInteger` | `thisexponent` <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/ArithmeticException` | `exponent` is negative. (This would cause the operation to yield a non-integer value.) |

### probablePrime

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static BigInteger probablePrime (int bitLength, 
                Random rnd)
```

Returns 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^.

<br />

| Parameters ||
|---|---|
| `bitLength` | `int`: bitLength of the returned BigInteger. <br /> |
| `rnd` | `Random`: source of random bits used to select candidates to be tested for primality. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/math/BigInteger` | a BigInteger of `bitLength` bits that is probably prime <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/ArithmeticException` | `bitLength < 2` or `bitLength` is too large. |

**See also:**

- `https://developer.android.com/reference/java/math/BigInteger#bitLength()`

### remainder

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public BigInteger remainder (BigInteger val)
```

Returns a BigInteger whose value is `(this % val)`.

<br />

| Parameters ||
|---|---|
| `val` | `BigInteger`: value by which this BigInteger is to be divided, and the remainder computed. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/math/BigInteger` | `this % val` <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/ArithmeticException` | if `val` is zero. |

### setBit

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public BigInteger setBit (int n)
```

Returns a BigInteger whose value is equivalent to this BigInteger with the designated bit set. (Computes `(this | (1<<n))`.)

<br />

| Parameters ||
|---|---|
| `n` | `int`: index of bit to set. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/math/BigInteger` | `this | (1<<n)` <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/ArithmeticException` | `n` is negative. |

### shiftLeft

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public BigInteger shiftLeft (int n)
```

Returns a BigInteger whose value is `(this << n)`. The shift distance, `n`, may be negative, in which case this method performs a right shift. (Computes `floor(this * 2n)`.)

<br />

| Parameters ||
|---|---|
| `n` | `int`: shift distance, in bits. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/math/BigInteger` | `this << n` <br /> |

**See also:**

- `https://developer.android.com/reference/java/math/BigInteger#shiftRight(int)`

### shiftRight

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public BigInteger shiftRight (int n)
```

Returns 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. (Computes `floor(this / 2n)`.)

<br />

| Parameters ||
|---|---|
| `n` | `int`: shift distance, in bits. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/math/BigInteger` | `this >> n` <br /> |

**See also:**

- `https://developer.android.com/reference/java/math/BigInteger#shiftLeft(int)`

### shortValueExact

Added in [API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public short shortValueExact ()
```

Converts this `BigInteger` to a `short`, checking for lost information. If the value of this `BigInteger` is out of the range of the `short` type, then an `ArithmeticException` is thrown.

<br />

| Returns ||
|---|---|
| `short` | this `BigInteger` converted to a `short`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/ArithmeticException` | if the value of `this` will not exactly fit in a `short`. |

**See also:**

- `https://developer.android.com/reference/java/lang/Number#shortValue()`

### signum

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int signum ()
```

Returns the signum function of this BigInteger.

<br />

| Returns ||
|---|---|
| `int` | -1, 0 or 1 as the value of this BigInteger is negative, zero or positive. <br /> |

### sqrt

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public BigInteger sqrt ()
```

Returns the integer square root of this BigInteger. The integer square root of the corresponding mathematical integer `n` is the largest mathematical integer `s` such that `s*s <= n`. It is equal to the value of `floor(sqrt(n))`, where `sqrt(n)` denotes the real square root of `n` treated 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.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/math/BigInteger` | the integer square root of `this` <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/ArithmeticException` | if `this` is negative. (The square root of a negative integer `val` is `(i * sqrt(-val))` where *i* is the *imaginary unit* and is equal to `sqrt(-1)`.) |

### sqrtAndRemainder

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public BigInteger[] sqrtAndRemainder ()
```

Returns an array of two BigIntegers containing the integer square root `s` of `this` and its remainder `this - s*s`, respectively.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/math/BigInteger` | an array of two BigIntegers with the integer square root at offset 0 and the remainder at offset 1 <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/ArithmeticException` | if `this` is negative. (The square root of a negative integer `val` is `(i * sqrt(-val))` where *i* is the *imaginary unit* and is equal to `sqrt(-1)`.) |

**See also:**

- `https://developer.android.com/reference/java/math/BigInteger#sqrt()`

### subtract

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public BigInteger subtract (BigInteger val)
```

Returns a BigInteger whose value is `(this - val)`.

<br />

| Parameters ||
|---|---|
| `val` | `BigInteger`: value to be subtracted from this BigInteger. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/math/BigInteger` | `this - val` <br /> |

### testBit

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean testBit (int n)
```

Returns `true` if and only if the designated bit is set. (Computes `((this & (1<<n)) != 0)`.)

<br />

| Parameters ||
|---|---|
| `n` | `int`: index of bit to test. <br /> |

| Returns ||
|---|---|
| `boolean` | `true` if and only if the designated bit is set. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/ArithmeticException` | `n` is negative. |

### toByteArray

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public 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 `https://developer.android.com/reference/java/math/BigInteger#BigInteger(byte[])` constructor.)

<br />

| Returns ||
|---|---|
| `byte[]` | a byte array containing the two's-complement representation of this BigInteger. <br /> |

**See also:**

- `https://developer.android.com/reference/java/math/BigInteger#BigInteger(byte[])`

### toString

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String toString ()
```

Returns the decimal String representation of this BigInteger. The digit-to-character mapping provided by `Character.forDigit` is used, and a minus sign is prepended if appropriate. (This representation is compatible with the `https://developer.android.com/reference/java/math/BigInteger#BigInteger(java.lang.String)` constructor, and allows for String concatenation with Java's + operator.)

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | decimal String representation of this BigInteger. <br /> |

**See also:**

- `https://developer.android.com/reference/java/lang/Character#forDigit(int,%20int)`
- `https://developer.android.com/reference/java/math/BigInteger#BigInteger(java.lang.String)`

### toString

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String toString (int radix)
```

Returns the String representation of this BigInteger in the given radix. If the radix is outside the range from `https://developer.android.com/reference/java/lang/Character#MIN_RADIX` to `https://developer.android.com/reference/java/lang/Character#MAX_RADIX` inclusive, it will default to 10 (as is the case for `Integer.toString`). The digit-to-character mapping provided by `Character.forDigit` is used, and a minus sign is prepended if appropriate. (This representation is compatible with the `https://developer.android.com/reference/java/math/BigInteger#BigInteger(java.lang.String,%20int)` constructor.)

<br />

| Parameters ||
|---|---|
| `radix` | `int`: radix of the String representation. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | String representation of this BigInteger in the given radix. <br /> |

**See also:**

- `https://developer.android.com/reference/java/lang/Integer#toString()`
- `https://developer.android.com/reference/java/lang/Character#forDigit(int,%20int)`
- `https://developer.android.com/reference/java/math/BigInteger#BigInteger(java.lang.String,%20int)`

### valueOf

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static BigInteger valueOf (long val)
```

Returns a BigInteger whose value is equal to that of the specified `long`.

<br />

##### 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` | `long`: value of the BigInteger to return. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/math/BigInteger` | a BigInteger with the specified value. <br /> |

### xor

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public BigInteger xor (BigInteger val)
```

Returns 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.)

<br />

| Parameters ||
|---|---|
| `val` | `BigInteger`: value to be XOR'ed with this BigInteger. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/math/BigInteger` | `this ^ val` <br /> |