BigInteger Class

Definition

Immutable arbitrary-precision integers.

[Android.Runtime.Register("java/math/BigInteger", DoNotGenerateAcw=true)]
public class BigInteger : Java.Lang.Number, IDisposable, Java.Interop.IJavaPeerable, Java.Lang.IComparable
[<Android.Runtime.Register("java/math/BigInteger", DoNotGenerateAcw=true)>]
type BigInteger = class
    inherit Number
    interface ISerializable
    interface IJavaObject
    interface IDisposable
    interface IJavaPeerable
    interface IComparable
Inheritance
BigInteger
Attributes
Implements

Remarks

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<sup>Integer.MAX_VALUE</sup> (exclusive) to +2<sup>Integer.MAX_VALUE</sup> (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<sup>500000000</sup>.

Added in 1.1.

Java documentation for java.math.BigInteger.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Constructors

BigInteger(Byte[])

Translates a byte array containing the two's-complement binary representation of a BigInteger into a BigInteger.

BigInteger(Byte[], Int32, Int32)

Translates a byte sub-array containing the two's-complement binary representation of a BigInteger into a BigInteger.

BigInteger(Int32, Byte[])

Translates the sign-magnitude representation of a BigInteger into a BigInteger.

BigInteger(Int32, Byte[], Int32, Int32)

Translates the sign-magnitude representation of a BigInteger into a BigInteger.

BigInteger(Int32, Int32, Random)

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

BigInteger(Int32, Random)

Constructs a randomly generated BigInteger, uniformly distributed over the range 0 to (2<sup>numBits</sup> - 1), inclusive.

BigInteger(IntPtr, JniHandleOwnership)

A constructor used when creating managed representations of JNI objects; called by the runtime.

BigInteger(String)

Translates the decimal String representation of a BigInteger into a BigInteger.

BigInteger(String, Int32)

Translates the String representation of a BigInteger in the specified radix into a BigInteger.

Properties

Class

Returns the runtime class of this Object.

(Inherited from Object)
Handle

The handle to the underlying Android instance.

(Inherited from Object)
JniIdentityHashCode (Inherited from Object)
JniPeerMembers
LowestSetBit

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

One

The BigInteger constant one.

PeerReference (Inherited from Object)
Ten

The BigInteger constant ten.

ThresholdClass

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

ThresholdType

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Two

The BigInteger constant two.

Zero

The BigInteger constant zero.

Methods

Abs()

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

Add(BigInteger)

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

And(BigInteger)

Returns a BigInteger whose value is (this & val).

AndNot(BigInteger)

Returns a BigInteger whose value is (this & ~val).

BitCount()

Returns the number of bits in the two's complement representation of this BigInteger that differ from its sign bit.

BitLength()

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

ByteValue()

Returns the value of the specified number as a byte.

(Inherited from Number)
ByteValueExact()

Converts this BigInteger to a byte, checking for lost information.

ClearBit(Int32)

Returns a BigInteger whose value is equivalent to this BigInteger with the designated bit cleared.

Clone()

Creates and returns a copy of this object.

(Inherited from Object)
CompareTo(BigInteger)

Compares this BigInteger with the specified BigInteger.

Dispose() (Inherited from Object)
Dispose(Boolean) (Inherited from Object)
Divide(BigInteger)

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

DivideAndRemainder(BigInteger)

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

DoubleValue()

Converts this BigInteger to a double.

Equals(Object)

Indicates whether some other object is "equal to" this one.

(Inherited from Object)
FlipBit(Int32)

Returns a BigInteger whose value is equivalent to this BigInteger with the designated bit flipped.

FloatValue()

Converts this BigInteger to a float.

Gcd(BigInteger)

Returns a BigInteger whose value is the greatest common divisor of abs(this) and abs(val).

GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
IntValue()

Converts this BigInteger to an int.

IntValueExact()

Converts this BigInteger to an int, checking for lost information.

IsProbablePrime(Int32)

Returns true if this BigInteger is probably prime, false if it's definitely composite.

JavaFinalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

(Inherited from Object)
LongValue()

Converts this BigInteger to a long.

LongValueExact()

Converts this BigInteger to a long, checking for lost information.

Max(BigInteger)

Returns the maximum of this BigInteger and val.

Min(BigInteger)

Returns the minimum of this BigInteger and val.

Mod(BigInteger)

Returns a BigInteger whose value is (this mod m).

ModInverse(BigInteger)

Returns a BigInteger whose value is (this<sup>-1</sup> mod m).

ModPow(BigInteger, BigInteger)

Returns a BigInteger whose value is (this<sup>exponent</sup> mod m).

Multiply(BigInteger)

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

Negate()

Returns a BigInteger whose value is (-this).

NextProbablePrime()

Returns the first integer greater than this BigInteger that is probably prime.

Not()

Returns a BigInteger whose value is (~this).

Notify()

Wakes up a single thread that is waiting on this object's monitor.

(Inherited from Object)
NotifyAll()

Wakes up all threads that are waiting on this object's monitor.

(Inherited from Object)
Or(BigInteger)

Returns a BigInteger whose value is (this | val).

Pow(Int32)

Returns a BigInteger whose value is (this<sup>exponent</sup>).

ProbablePrime(Int32, Random)

Returns a positive BigInteger that is probably prime, with the specified bitLength.

Remainder(BigInteger)

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

SetBit(Int32)

Returns a BigInteger whose value is equivalent to this BigInteger with the designated bit set.

SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
ShiftLeft(Int32)

Returns a BigInteger whose value is (this << n).

ShiftRight(Int32)

Returns a BigInteger whose value is (this >> n).

ShortValue()

Returns the value of the specified number as a short.

(Inherited from Number)
ShortValueExact()

Converts this BigInteger to a short, checking for lost information.

Signum()

Returns the signum function of this BigInteger.

Sqrt()

Returns the integer square root of this BigInteger.

SqrtAndRemainder()

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

Subtract(BigInteger)

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

TestBit(Int32)

Returns true if and only if the designated bit is set.

ToArray<T>() (Inherited from Object)
ToByteArray()

Returns a byte array containing the two's-complement representation of this BigInteger.

ToString()

Returns a string representation of the object.

(Inherited from Object)
ToString(Int32)

Returns the String representation of this BigInteger in the given radix.

UnregisterFromRuntime() (Inherited from Object)
ValueOf(Int64)

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

Wait()

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>.

(Inherited from Object)
Wait(Int64)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Wait(Int64, Int32)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Xor(BigInteger)

Returns a BigInteger whose value is (this ^ val).

Explicit Interface Implementations

IComparable.CompareTo(Object)
IJavaPeerable.Disposed() (Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Object)
IJavaPeerable.Finalized() (Inherited from Object)
IJavaPeerable.JniManagedPeerState (Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Object)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Applies to