📜  Java.math.BigInteger类

📅  最后修改于: 2020-11-14 06:00:28             🧑  作者: Mango


介绍

java.math.BigInteger类为Java的所有原始整数运算符以及java.lang.Math中的所有相关方法提供操作类似物。

它还提供用于模块化算术,GCD计算,素数测试,素数生成,位操作以及其他一些杂项运算的操作。所有操作的行为都好像BigIntegers用二进制补码表示。

算术运算和按位逻辑运算的语义分别类似于Java的整数算术运算运算符和Java的按位整数运算符。移位运算的语义扩展了Java移位运算符的语义,以允许负移位距离。

比较操作执行带符号整数比较。提供了模块化算术运算来计算残差,执行幂运算和计算乘法逆。位操作在其操作数的二进制补码表示的一位上进行操作。

为任何输入参数传递空对象引用时,此类中的所有方法和构造函数都将引发NullPointerException。

类声明

以下是java.math.BigInteger类的声明-

public class BigInteger
   extends Number
      implements Comparable

领域

以下是java.math.BigInteger类的字段-

  • 静态BigInteger ONE -BigInteger常数1。

  • 静态BigInteger TEN -BigInteger常数10。

  • 静态BigInteger零-BigInteger常数零。

类的构造函数

Sr.No. Constructor & Description
1

BigInteger(byte[] val)

This constructor is used to translate a byte array containing the two’s-complement binary representation of a BigInteger into a BigInteger.

2

BigInteger(int signum, byte[] magnitude)

This constructor is used to translate the sign-magnitude representation of a BigInteger into a BigInteger.

3

BigInteger(int bitLength, int certainty, Random rnd)

This constructor is used to construct a randomly generated positive BigInteger that is probably prime, with the specified bitLength.

4

BigInteger(int numBits, Random rnd)

This constructor is used to construct a randomly generated BigInteger, uniformly distributed over the range 0 to (2numBits – 1), inclusive.

5

BigInteger(String val)

This constructor is used to translate the decimal String representation of a BigInteger into a BigInteger.

6

BigInteger(String val, int radix)

This constructor is used to translate the String representation of a BigInteger in the specified radix into a BigInteger.

类方法

Sr.No. Method & Description
1 BigInteger abs()

This method returns a BigInteger whose value is the absolute value of this BigInteger.

2 BigInteger add(BigInteger val)

This method returns a BigInteger whose value is (this + val).

3 BigInteger and(BigInteger val)

This method returns a BigInteger whose value is (this & val).

4 BigInteger andNot(BigInteger val)

This method returns a BigInteger whose value is (this & ~val).

5 int bitCount()

This method returns the number of bits in the two’s complement representation of this BigInteger that differ from its sign bit.

6 int bitLength()

This method returns the number of bits in the minimal two’s-complement representation of this BigInteger, excluding a sign bit.

7 BigInteger clearBit(int n)

This method returns a BigInteger whose value is equivalent to this BigInteger with the designated bit cleared.

8 int compareTo(BigInteger val)

This method compares this BigInteger with the specified BigInteger.

9 BigInteger divide(BigInteger val)

This method returns a BigInteger whose value is (this / val).

10 BigInteger[ ] divideAndRemainder(BigInteger val)

This method returns an array of two BigIntegers containing (this / val) followed by (this % val).

11 double doubleValue()

This method converts this BigInteger to a double.

12 boolean equals(Object x)

This method compares this BigInteger with the specified Object for equality.

13 BigInteger flipBit(int n)

This method returns a BigInteger whose value is equivalent to this BigInteger with the designated bit flipped.

14 float floatValue()

This method converts this BigInteger to a float.

15 BigInteger gcd(BigInteger val)

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

16 int getLowestSetBit()

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

17 int hashCode()

This method returns the hash code for this BigInteger.

18 int intValue()

This method converts this BigInteger to an int.

19 boolean isProbablePrime(int certainty)

This method returns true if this BigInteger is probably prime, false if it’s definitely composite.

20 long longValue()

This method converts this BigInteger to a long.

21 BigInteger max(BigInteger val)

This method returns the maximum of this BigInteger and val.

22 BigInteger min(BigInteger val)

This method returns the minimum of this BigInteger and val.

23 BigInteger mod(BigInteger m)

This method returns a BigInteger whose value is (this mod m).

24 BigInteger modInverse(BigInteger m)

This method returns a BigInteger whose value is (this-1 mod m).

25 BigInteger modPow(BigInteger exponent, BigInteger m)

This method returns a BigInteger whose value is (thisexponent mod m).

26 BigInteger multiply(BigInteger val)

This method returns a BigInteger whose value is (this * val).

27 BigInteger negate()

This method returns a BigInteger whose value is (-this).

28 BigInteger nextProbablePrime()

This method returns the first integer greater than this BigInteger that is probably prime.

29 BigInteger not()

This method returns a BigInteger whose value is (~this).

30 BigInteger or(BigInteger val)

This method returns a BigInteger whose value is (this | val).

31 BigInteger pow(int exponent)

This method returns a BigInteger whose value is (thisexponent).

32 static BigInteger probablePrime(int bitLength, Random rnd)

This method returns a positive BigInteger that is probably prime, with the specified bitLength.

33 BigInteger remainder(BigInteger val)

This method returns a BigInteger whose value is (this % val).

34 BigInteger setBit(int n)

This method returns a BigInteger whose value is equivalent to this BigInteger with the designated bit set.

35 BigInteger shiftLeft(int n)

This method returns a BigInteger whose value is (this << n).

36 BigInteger shiftRight(int n)

This method returns a BigInteger whose value is (this >> n).

37 intsignum()

This method returns the signum function of this BigInteger.

38 BigInteger subtract(BigInteger val)

This method returns a BigInteger whose value is (this – val).

39 boolean testBit(int n)

This method returns true if and only if the designated bit is set.

40 byte[ ] toByteArray()

This method returns a byte array containing the two’s-complement representation of this BigInteger.

41 String toString()

This method returns the decimal String representation of this BigInteger.

42 String toString(int radix)

This method returns the String representation of this BigInteger in the given radix.

43 static BigInteger valueOf(long val)

This method returns a BigInteger whose value is equal to that of the specified long.

44 BigInteger xor(BigInteger val)

This method returns a BigInteger whose value is (this ^ val).