java BigInteger类

BigInteger类是java用来处理超长位数字所创建的一种类,在包java.math.BigInteger中

构造方法:

BigInteger(byte[] val) 
          将包含 BigInteger 的二进制补码表示形式的 byte 数组转换为 BigInteger。
BigInteger(int signum, byte[] magnitude) 
          将 BigInteger 的符号-数量表示形式转换为 BigInteger。
BigInteger(int bitLength, int certainty, Random rnd) 
          构造一个随机生成的正 BigInteger,它可能是一个具有指定 bitLength 的素数。
BigInteger(int numBits, Random rnd) 
          构造一个随机生成的 BigInteger,它是在 0 到 (2numBits - 1)(包括)范围内均匀分布的值。
BigInteger(String val) 
          将 BigInteger 的十进制字符串表示形式转换为 BigInteger。
BigInteger(String val, int radix) 
          将指定基数的 BigInteger 的字符串表示形式转换为 BigInteger。
由此可见,我们无法用int,long等类型来构造,只能使用String型,提供以下方法;
int a = 12345;
BigInteger bi = new BigInteger(a + "");
BigInteger 的转换:
int intValue() 
          将此 BigInteger 转换为 int。

 float  floatValue() 
          将此 BigInteger 转换为 floatdouble doubleValue() 
          将此 BigInteger 转换为 double
BigInteger 的加减乘除:
加减
BigInteger  multiply(BigInteger val) 
          返回其值为 (this * val) 的 BigInteger。

乘除
BigInteger  remainder(BigInteger val) 
          返回其值为 (this % val) 的 BigInteger。

取负
BigInteger  negate() 
          返回其值是 (-this) 的 BigInteger。

取余
BigInteger  subtract(BigInteger val) 
          返回其值为 (this - val) 的 BigInteger。
使用方法:
比如我们要加一个整数a:
int a = 12345;
BigInteger bi = new BigInteger(a + "");

bi = bi.subtract(new BigIntreger(-a + ""));
减,乘,除请大家自行扩展~~~
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值