BigInteger

fun BigInteger(val: ByteArray, off: Int = 0, len: Int = `val`.size)

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.

Since

9

Parameters

val

byte array containing a sub-array which is the big-endian two's-complement binary representation of a BigInteger.

off

the start offset of the binary representation.

len

the number of bytes to use.

Throws

val is zero bytes long.

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.

fun BigInteger(signum: Int, magnitude: ByteArray, off: Int = 0, len: Int = magnitude.size)

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.

Since

9

Parameters

signum

_signum of the number (-1 for negative, 0 for zero, 1 for positive).

magnitude

big-endian binary representation of the magnitude of the number.

off

the start offset of the binary representation.

len

the number of bytes to use.

Throws

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

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.

fun BigInteger(val: String, radix: Int = 10)

Translates the String representation of a BigInteger in the specified radix into a BigInteger. The String representation consists of an optional subtract or plus sign followed by a sequence of one or more digits in the specified radix. The character-to-digit mapping is provided by Character.digit. The String may not contain any extraneous characters (whitespace, for example).

See also

Character.digit

Parameters

val

String representation of BigInteger.

radix

radix to be used in interpreting val.

Throws

val is not a valid representation of a BigInteger in the specified radix, or radix is outside the range from CHAR_MIN_RADIX to CHAR_MAX_RADIX, inclusive.

fun BigInteger(numBits: Int, rnd: Random)

Constructs a randomly generated BigInteger, uniformly distributed over the range 0 to (2<sup>numBits</sup> - 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.

See also

.bitLength

Parameters

numBits

maximum bitLength of the new BigInteger.

rnd

source of randomness to be used in computing the new BigInteger.

Throws

fun BigInteger(bitLength: Int, certainty: Int, rnd: Random)

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

See also

.bitLength

Parameters

bitLength

bitLength of the returned BigInteger.

certainty

a measure of the uncertainty that the caller is willing to tolerate. The probability that the new BigInteger represents a prime number will exceed (1 - 1/2<sup>certainty</sup>). The execution time of this constructor is proportional to the value of this parameter.

rnd

source of random bits used to select candidates to be tested for primality.

Throws

bitLength < 2 or bitLength is too large.