当前位置: 首页 > article >正文

BigInteger 的常用函数分类说明

一、核心算术运算

方法名功能说明示例(结合代码场景)
add(BigInteger val)加法运算BigInteger sum = a.add(b);
subtract(BigInteger val)减法运算BigInteger diff = a.subtract(b);
multiply(BigInteger val)乘法运算BigInteger product = a.multiply(b);
divide(BigInteger val)除法运算(取商)BigInteger quotient = a.divide(b);
remainder(BigInteger val)取余运算BigInteger rem = a.remainder(b);
mod(BigInteger m)取模(确保结果非负)BigInteger mod = a.mod(m);
pow(int exponent)幂运算BigInteger power = a.pow(10);
gcd(BigInteger val)最大公约数(GCD)BigInteger gcd = a.gcd(b);

二、比较与逻辑判断

方法名功能说明示例(结合代码场景)
compareTo(BigInteger val)比较大小(返回-1/0/1)if (a.compareTo(b) > 0) { ... }
equals(Object x)相等性判断if (a.equals(BigInteger.ZERO)) { ... }
isProbablePrime(int certainty)质数概率测试if (a.isProbablePrime(100)) { ... }

三、位运算与二进制操作

方法名功能说明示例(结合代码场景)
and(BigInteger val)按位与BigInteger result = a.and(b);
or(BigInteger val)按位或BigInteger result = a.or(b);
xor(BigInteger val)按位异或BigInteger result = a.xor(b);
not()按位取反BigInteger result = a.not();
shiftLeft(int n)左移 n 位BigInteger shifted = a.shiftLeft(3);
shiftRight(int n)右移 n 位(符号扩展)BigInteger shifted = a.shiftRight(2);

四、工具与转换方法

方法名功能说明示例(结合代码场景)
toString()转为十进制字符串String s = a.toString();
toString(int radix)按指定进制转为字符串String bin = a.toString(2);
intValue()转为 int(可能溢出)int num = a.intValue();
longValue()转为 long(可能溢出)long num = a.longValue();
valueOf(long val)静态方法:创建对象BigInteger num = BigInteger.valueOf(42);

http://www.kler.cn/a/593803.html

相关文章:

  • 23种设计模式中的状态模式
  • vue-tsc 使用问题及解决方法
  • 鸿蒙Next开发与未来发展的变革:全场景操作系统的全新纪元
  • Linux内核IPv4路由选择子系统
  • 汇川EASY系列之以太网通讯(MODBUS_TCP做从站)
  • MySQL:数据库基础
  • HTML5学习成果(仅HTML部分)
  • 无需qt-creator,使用Trae从0到1生成qt的开发、构建、调试环境
  • 网络安全常识科普(百问百答)
  • 游戏引擎学习第169天
  • D. Equalization【Educational Codeforces Round 176 (Rated for Div. 2)】
  • C++进阶——红黑树的实现
  • RC5解密工具
  • Canal 解析与 Spring Boot 整合实战
  • 大模型之蒸馏模型
  • 51c大模型~合集73
  • K8S学习之基础三十五:k8s之Prometheus部署模式
  • python全栈-Redis从入门到开发
  • 蓝桥杯备考----小贪心+分类讨论问题---Popsicle
  • 版本控制器Git ,Gitee如何连接Linux Gitee和Github区别