用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
热门推荐
10 最新中秋祝福语简短霸气
11 关于读博祝福语简短
12 学会放下祝福语大全简短
13 高校女生祝福语大全简短
14 简短独特生日贺卡祝福语
15 金哥哥结婚祝福语简短
16 哥哥生孩子祝福语简短
17 出差祝福语简短10字
18 写给男性朋友祝福语简短