BigInteger abs() 返回大整数的绝对值
BigInteger add(BigInteger val) 返回两个大整数的和
BigInteger and(BigInteger val) 返回两个大整数的按位与的结果
BigInteger andNot(BigInteger val) 返回两个大整数与非的结果
BigInteger divide(BigInteger val) 返回两个大整数的商
double doubleValue() 返回大整数的double类型的值
float floatValue() 返回大整数的float类型的值
BigInteger gcd(BigInteger val) 返回大整数的最大公约数
int intValue() 返回大整数的整型值
long longValue() 返回大整数的long型值
BigInteger max(BigInteger val) 返回两个大整数的最大者
BigInteger min(BigInteger val) 返回两个大整数的最小者
BigInteger mod(BigInteger val) 用当前大整数对val求模
BigInteger multiply(BigInteger val) 返回两个大整数的积
BigInteger negate() 返回当前大整数的相反数
BigInteger not() 返回当前大整数的非
BigInteger or(BigInteger val) 返回两个大整数的按位或
BigInteger pow(int exponent) 返回当前大整数的exponent次方
BigInteger remainder(BigInteger val) 返回当前大整数除以val的余数
BigInteger shiftLeft(int n) 将当前大整数左移n位后返回
BigInteger shiftRight(int n) 将当前大整数右移n位后返回
BigInteger subtract(BigInteger val)返回两个大整数相减的结果
byte[] toByteArray(BigInteger val)将大整数转换成二进制反码保存在byte数组中
String toString() 将当前大整数转换成十进制的字符串形式
BigInteger xor(BigInteger val) 返回两个大整数的异或
String s = "-23423432";
BigInteger bs = new BigInteger(s);
System.out.println(bs); //-23423432
BigInteger ba = bs.abs();
System.out.println(ba); //23423432
String s = "-23423432";
String ss = "23423433";
BigInteger bs = new BigInteger(s);
BigInteger bss = new BigInteger(ss);
BigInteger sad = bs.add(bss);
System.out.println(sad); //1
String s = "23423432";
String ss = "23423433";
BigInteger bs = new BigInteger(s);
BigInteger bss = new BigInteger(ss);
BigInteger sad = bss.subtract(bs); //bss-bs
System.out.println(sad); //1
String s = "2";
String ss = "3";
BigInteger bs = new BigInteger(s);
BigInteger bss = new BigInteger(ss);
BigInteger sad = bss.multiply(bs);
System.out.println(sad);
String s = "3";
String ss = "7";
BigInteger bs = new BigInteger(s);
BigInteger bss = new BigInteger(ss);
BigInteger sad = bss.divide(bs); // bss/bs
System.out.println(sad); //2
String s = "-3";
String ss = "7";
BigInteger bs = new BigInteger(s);
BigInteger bss = new BigInteger(ss);
BigInteger nebs = bs.negate();
BigInteger nebss = bss.negate();
System.out.println(nebs); // 3
System.out.println(nebss); // -7
注意在小数中的使用!与mod()对照。
String s = "3";
String ss = "7";
BigInteger bs = new BigInteger(s);
BigInteger bss = new BigInteger(ss);
BigInteger nebs = bss.remainder(bs); // bss%bs
System.out.println(nebs); // 1
注意在小数中不能使用!与remainder()对照。
String s = "3";
String ss = "7";
BigInteger bs = new BigInteger(s);
BigInteger bss = new BigInteger(ss);
BigInteger nebs = bss.mod(bs);
System.out.println(nebs); //1
String s = "2";
int p = 4;
BigInteger bs = new BigInteger(s);
BigInteger nebs = bs.pow(p);
System.out.println(nebs);
String string1 = new BigInteger("20", 10).toString(2);
System.out.println("十进制的20转换成二进制是:"+string1);
String string2 = new BigInteger("20", 10).toString(8);
System.out.println("十进制的20转换成八进制是:"+string2);
String string3 = new BigInteger("20", 10).toString(16);
System.out.println("十进制的20转换成十六进制是:"+string3);
//out
十进制的20转换成二进制是:10100
十进制的20转换成八进制是:24
十进制的20转换成十六进制是:14
String string4 = new BigInteger("110", 2).toString(10);
System.out.println("二进制的110转换成十进制是:"+string4);
String string5 = new BigInteger("110", 8).toString(10);
System.out.println("八进制的110转换成十进制是:"+string5);
String string6 = new BigInteger("110", 16).toString(10);
System.out.println("十六进制的110转换成十进制是:"+string6);
//out
二进制的110转换成十进制是:6
八进制的110转换成十进制是:72
十六进制的110转换成十进制是:272