用Java将大整数解析并格式化为二进制
首先,获取两个BigInteger对象并设置值。
BigInteger one, two;
one = new BigInteger("99");
two = new BigInteger("978");现在,将BigInteger对象“two”解析为Binary。
two = new BigInteger("1111010010", 2);
String str = two.toString(2);上面,我们使用了以下构造函数。在这里,BigInteger构造函数和toString()方法的Binary基数均设置为2。
BigInteger(Stringval,intradix)
此构造函数用于将指定基数中的BigInteger的String表示形式转换为BigInteger。
以下是一个例子-
示例
import java.math.*;
public class Demo {
public static void main(String[] args) {
BigInteger one, two;
one = new BigInteger("99");
// parsing BigInteger object "two" into Binary
two = new BigInteger("1111010010", 2);
String str = two.toString(2);
System.out.println("Result (BigInteger) : " +one);
System.out.println("Result after parsing : " +str);
}
}输出结果
Result (BigInteger) : 99 Result after parsing : 1111010010
热门推荐
3 足球队祝福语简短
10 婚庆花篮祝福语简短大气
11 宝宝生日祝福语大全简短
12 公司五一祝福语简短最新
13 收生日红包祝福语 简短
14 婚礼祝福语简短情话短句
15 新年祝福语简短给孩子
16 简短霸气的考试祝福语
17 感谢父母的简短祝福语
18 特别的端午祝福语简短