BigInteger in Java

Source: Internet
Author: User
Tags comparable
For documents on the copied API, BigInteger has no problem in dealing with general high precision. Java. math
BigInteger
java.lang.Object      java.lang.Number          java.math.BigInteger
All Implemented interfaces:
Serializable,
Comparable <BigInteger>
public class BigInteger
Extends Number
Implements Comparable <BigInteger>
 

An integer of any precision that is not changeable. In all operations, BigInteger (such as the basic integer type of Java) is expressed in the form of binary complement ). BigInteger provides the counterparts of all basic integer operators in Java and all related methods of java. lang. Math. BigInteger also provides the following operations: modulo arithmetic, GCD calculation, prime number testing, prime number generation, bit operations, and some other operations.

The semantics of arithmetic operations completely imitates the semantics of Java integer Arithmetic Operators, suchThe Java Language Specification. For example, it is thrown using zero as the Division of the divisor.ArithmeticExceptionAnd the division of negative numbers by positive numbers produces a negative (or zero) remainder. Details about overflow in Spec are ignored, because the actual size set by BigIntegers can meet the needs of the operation results.

The semantics of the displacement operation extends the semantics of the Java displacement operator to allow Negative displacement distance. The right shift operation with a negative displacement distance will result in the left shift operation, and vice versa. Ignore the unsigned right-shift operator (>>>) because this operation is meaningless when combined with the "Infinite word size" abstraction provided by this class.

The semantics of the bit-by-bit logical operation completely imitates the semantics of the Java bit-by-bit integer operator. Before the operation is executed, the binary operator (And,Or,Xor) Implicitly executes symbol extension on the shorter operands of the two operands.

The comparison operation performs a signed integer comparison, similar to the comparison between Java Relational operators and equality operators.

The provided modulo arithmetic operations are used to calculate the remainder, power, and multiplication reversible elements. These methods always return non-negative results in the range0And(Modulus-1)(Inclusive.

Bitwise Operations perform operations on a single bitwise in the binary complement representation of its operands. If necessary, the operand will contain the specified bit through the extension symbol. A single-bit operation cannot generate a BigInteger that is different from the BigInteger symbol being operated, because they only affect a single bit, in addition, the "infinite word size" abstraction provided by this class ensures an infinite number of "virtual symbol bits" before each BigInteger.

For simplicity and clarity, pseudocode is used in the description of the entire BigInteger method. Pseudo-code expression(I + j)Is "The value is BigInteger
IAdd BigIntegerJBigInteger. Pseudo-code expression(I = j)Is "if and only if BigIntegerIBigInteger
JOnly when the value is the sameTrue. Other pseudo-code expressions can be interpreted similarly.

When a null Object Reference is passed for any input parameter, all methods and constructor in this class will throwNullPointerException.

Field Abstract
Static BigInteger ONE
The constant 1 of BigInteger.
Static BigInteger TEN
The constant 10 of BigInteger.
Static BigInteger ZERO
The constant 0 of BigInteger.
Constructor Summary
BigInteger (byte [] val)
Converts a byte array containing the BigInteger binary complement representation to a BigInteger.
BigInteger (int signum, byte [] magnitude)
Convert the BigInteger symbol-quantity to BigInteger.
BigInteger (int bitLength, int certainty, Random rnd)
Construct a random positive BigInteger, which may be a prime number with a specified bitLength.
BigInteger (int numBits, Random rnd)
Construct a random BigInteger that is evenly distributed from 0 to (2 numBits-1) (inclusive.
BigInteger (String val)
Converts the decimal string representation of BigInteger to BigInteger.
BigInteger (String val, int radix)
Converts the string representation of the specified BigInteger to BigInteger.
Method Summary
BigInteger abs ()
Returns the BigInteger whose value is the absolute value of this BigInteger.
BigInteger add (BigInteger val)
Return the BigInteger whose value is (this + val.
BigInteger and (BigInteger val)
Return the BigInteger whose value is (this & val.
BigInteger andNot (BigInteger val)
The returned value is (this &~ Val) BigInteger.
Int bitCount ()
Returns the number of bits in the BigInteger binary complement representation that are different from the symbol.
Int bitLength ()
Returns the minimum number of digits in the BigInteger binary complement representation, excluding the symbol bit.
BigInteger clearBit (int n)
The returned value is equivalent to clearing the BigInteger.
Int compareTo (BigInteger val)
Compare the BigInteger with the specified BigInteger.
BigInteger divide (BigInteger val)
Return the BigInteger whose value is (this/val.
BigInteger [] divideAndRemainder (BigInteger val)
Returns an array of two bigintegers including (this/val) and (this % val.
Double doubleValue ()
Convert this BigInteger to double.
Boolean equals (Object x)
Compare the equality between the BigInteger and the specified Object.
BigInteger flipBit (int n)
The returned value is equivalent to the BigInteger that is used to locate the flipped value.
Float floatValue ()
Convert this BigInteger to float.
BigInteger gcd (BigInteger val)
Return a BigInteger whose value is the maximum common divisor of abs (this) and abs (val.
Int getLowestSetBit ()
Returns the 1-bit index of the rightmost (least bit) of this BigInteger (that is, the 0-bit number between the right end of the byte and the rightmost 1-bit of the local byte ).
Int hashCode ()
Returns the hash code of this BigInteger.
Int intValue ()
Convert this BigInteger to int.
Boolean isProbablePrime (int certainty)
If this BigInteger may be a prime number, true is returned. If it must be a combination, false is returned.
Long longValue ()
Convert this BigInteger to long.
BigInteger max (BigInteger val)
Returns the maximum values of BigInteger and val.
BigInteger min (BigInteger val)
Returns the minimum values of BigInteger and val.
BigInteger mod (BigInteger m)
Return the BigInteger whose value is (this mod m.
BigInteger modInverse (BigInteger m)
Return the BigInteger whose value is (this-1 mod m.
BigInteger modPow (BigInteger exponent, BigInteger m)
Return the BigInteger whose value is (thisexponent mod m.
BigInteger multiply (BigInteger val)
Return the BigInteger whose value is (this * val.
BigInteger negate ()
Return the BigInteger whose value is (-this.
BigInteger nextProbablePrime ()
Returns the first integer that is greater than the BigInteger that may be a prime number.
BigInteger not ()
Returns the value (~ This) BigInteger.
BigInteger or (BigInteger val)
Return the BigInteger whose value is (this | val.
BigInteger pow (int exponent)
Return the BigInteger whose value is (thisexponent.
Static BigInteger probablePrime (int bitLength, Random rnd)
Returns a positive BigInteger with a specified length, which may be a prime number.
BigInteger remainder (BigInteger val)
Return the BigInteger whose value is (this % val.
BigInteger setBit (int n)
The returned value is the BigInteger equivalent to the BigInteger specified for positioning.
BigInteger shiftLeft (int n)
Return the BigInteger whose value is (this <n.
BigInteger shiftRight (int n)
Return the BigInteger whose value is (this> n.
Int signum ()
Returns the positive and negative functions of this BigInteger.
BigInteger subtract (BigInteger val)
Return the BigInteger whose value is (this-val.
Boolean testBit (int n)
Returns true if only the specified bit is set.
Byte [] toByteArray ()
Returns a byte array that contains the binary complement representation of this BigInteger.
String toString ()
Returns the decimal string representation of this BigInteger.
String toString (int radix)
Returns the string representation of the given base of this BigInteger.
Static BigInteger valueOf (long val)
Returns the BigInteger whose value is equal to the value of the specified long.
BigInteger xor (BigInteger val)
Return the BigInteger whose value is (this ^ val.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.