java.math.BigInteger类提供操作类似所有Java的基本整数运算符和java.lang.Math中的所有相关的方法。
它还提供了模运算,GCD计算,素性测试,素数生成,位操作,和一些其他杂项业务操作。所有的操作行为,如果BigInteger的二进制补码委托表示法。
算术运算和按位逻辑运算的语义分别类似于那些Java的整数算术运算符和Java的按位整数运算符。移位操作的语义扩展那些Java的移位运算符的允许负移的距离。
比较操作执行有符号整数的比较。提供模块化的算术运算来计算残留,执行幂运算和计算乘法逆。位运算操作对他们的操作数的二进制补码表示的单个位。
在这个类将抛出NullPointerException,在所有方法和构造函数使用时,通过输入任何参数提供一个空的对象引用。
类声明
以下是java.math.BigInteger类的声明:
publicclassBigIntegerextendsNumberimplementsComparable
字段域
以下是java.math.BigInteger类中的字段:
static BigInteger ONE -- BigInteger的常量1。
static BigInteger TEN -- BigInteger的常量10。
static BigInteger ZERO -- BigInteger的常量0。
类构造函数
S.N.
构造函数 & 描述
1
BigInteger(byte[] val)
这个构造函数用于转换一个字节数组包含BigInteger的二进制补码,以二进制表示成一个BigInteger。
2
BigInteger(int signum, byte[] magnitude)
此构造函数用于将BigInteger的符号大小表示法转换成一个BigInteger值。
3
BigInteger(int bitLength, int certainty, Random rnd)
此构造函数用于构造一个随机生成正BigInteger的可能是以指定的bitLength的素数。
4
BigInteger(int numBits, Random rnd)
此构造函数用于构造一个随机生成的BigInteger,均匀分布在范围0到 (2numBits - 1), 包括.
5
BigInteger(String val)
此构造函数用于将BigInteger的十进制字符串表示形式转换成一个BigInteger值。
6
BigInteger(String val, int radix)
这个构造函数用于转换为BigInteger的指定基数为一个BigInteger的字符串表示形式。
类方法
S.N.
方法 & 描述
1
BigInteger abs()
此方法返回一个BigInteger,其值是此BigInteger的绝对值。
2
BigInteger add(BigInteger val)
此方法返回一个BigInteger,其值是(this + val).
3
BigInteger and(BigInteger val)
此方法返回一个BigInteger,其值是 (this & val).
4
BigInteger andNot(BigInteger val)
此方法返回一个BigInteger,其值是 (this & ~val).
5
int bitCount()
此方法返回此BigInteger的二进制补码表示的位,从符号位不同的数字。
6
int bitLength()
此方法返回位在此BigInteger的最小的二进制补码表示的数,不包括符号位。
7
BigInteger clearBit(int n)
此方法返回一个BigInteger,其值相当于此BigInteger与指定位清零。
8
int compareTo(BigInteger val)
此方法比较此BigInteger与指定的BigInteger。
9
BigInteger divide(BigInteger val)
此方法返回一个BigInteger,其值是 (this / val).
10
BigInteger[ ] divideAndRemainder(BigInteger val)
此方法返回一个包含两个BigIntegers:(this / val) 和 (this % val),其次是一个数组。
11
double doubleValue()
此方法此BigInteger转换为双精度double。
12
boolean equals(Object x)
此方法比较此BigInteger与指定对象是否相等。
13
BigInteger flipBit(int n)
此方法返回一个BigInteger,其值相当于此BigInteger与指定位翻转。
14
float floatValue()
此方法将BigInteger转换为float。
15
BigInteger gcd(BigInteger val)
此方法返回一个BigInteger,其值是绝对值的最大公约数:abs(this) 和abs(val)。
16
int getLowestSetBit()
此方法返回最右边的(最低阶)的索引在此BigInteger1比特(零比特的数量,以最右侧的1位的右侧)。
17
int hashCode()
此方法返回此BigInteger的哈希代码。
18
int intValue()
此方法此BigInteger转换为int。
19
boolean isProbablePrime(int certainty)
此方法返回true,如果此BigInteger是素数,其绝对复合数则返回false。
20
long longValue()
些方法将BigInteger转换为long。
23
BigInteger mod(BigInteger m)
此方法返回一个BigInteger,其值是(this mod m).
24
BigInteger modInverse(BigInteger m)
此方法返回一个BigInteger,其值是 (this-1 mod m).
26
BigInteger multiply(BigInteger val)
此方法返回一个BigInteger,其值是 (this * val).
27
BigInteger negate()
此方法返回一个BigInteger,其值是 (-this).
28
29
BigInteger not()
此方法返回一个BigInteger,其值是 (~this).
30
BigInteger or(BigInteger val)
此方法返回一个BigInteger,其值是 (this | val).
31
BigInteger pow(int exponent)
此方法返回一个BigInteger,其值是(thisexponent).
33
34
BigInteger setBit(int n)
此方法返回一个BigInteger,其值相当于此BigInteger与指定的位设置。
35
BigInteger shiftLeft(int n)
此方法返回一个BigInteger,其值是 (this << n).
36
BigInteger shiftRight(int n)
此方法返回一个BigInteger,其值是 (this >> n).
37
int signum()
This method returns the signum function of this BigInteger.
38
BigInteger subtract(BigInteger val)
此方法返回一个BigInteger,其值是 (this - val).
39
40
byte[ ] toByteArray()
此方法返回一个包含此BigInteger的二进制补码表示的字节数组。
41
String toString()
此方法返回此BigInteger的十进制字符串表示形式。
42
String toString(int radix)
此方法返回在给定的基数以BigInteger的字符串表示形式。
44
BigInteger xor(BigInteger val)
此方法返回一个BigInteger,其值是 (this ^ val).
¥ 我要打赏
纠错/补充
收藏
加QQ群啦,易百教程官方技术学习群
注意:建议每个人选自己的技术方向加群,同一个QQ最多限加 3 个群。