速通BigInteger
目录
速通BigInteger
- 首先需要导包
|
|
BigInteger的一些方法 | |
BigInteger bigInteger = new BigInteger("123456"); | 使用String进行初始化 |
abs() | 返回一个BigInteger。值为当前对象的绝对值 |
add(BigInteger) | 相加: bigInteger = bigInteger.add(new BigInteger("123456")); |
and(BigInteger) | 二进制AND(&)运算符: bigInteger = bigInteger.and(new BigInteger("123456")); |
andNot(BigInteger) | 二进制按位与非运算符,等同于and(BigTnteger.not()): bigInteger = bigInteger.andNot(new BigInteger("123456")); |
bitCount() | 该方法用于返回该BigInteger的补码表示中与符号位不同的位数 |
bitLength() | 返回二进制补码表示的长度 |
compareTo(BigInteger) | 返回二者比较结果:小于 -1, 等于 0, 大于 1 |
divide(BigInteger) | 相除,相当于"/" |
divideAndRemainder(BigInteger) | 返回一个BigInteger数组,第一位是截断结果(/),第二位是余数(%) |
doubleValue() | 返回对应的double值 |
gcd() | gcd(abs(val1), abs(val2)),使用gcd算法 |
intValue(), longValue() | 返回对应类型的值 |
max(), min() | 最大最小值 |
mod(BigInteger) | 相当于% |
multiply(BigInteger) | 相当于X |
negate() | 取相反数 |
pow(int) | 以该对象为基底,参数为幂 |
isProbablePrime(int certainty) | 是否是质数,certainty - 这一措施的调用者能容忍的不确定性,此方法的执行时间正比于该参数的值 |
shiftLeft(),shiftRight() | 左移,右移 |
subtract() | 相减 |