如何在java中乘以两个大数(比如512位)

时间:2010-05-29 11:44:22

标签: java

我想在java中将两个512位整数相乘,并存储result.suggest的一些方法来执行此操作。

2 个答案:

答案 0 :(得分:13)

我建议您使用java.math.BigInteger

答案 1 :(得分:7)

使用java.math.BigInteger

一个快速使用示例:

import java.math.BigInteger;

public class BigIntegerTest {
    public static void main(String[] args) {
        BigInteger b1 = new BigInteger("200000000000000000000000000000000001");
        BigInteger b2 = new BigInteger("400000000000000000000000000000000000");

        System.out.println(b1.multiply(b2));
        System.out.println(b1.bitCount());
        System.out.println(b1.pow(13));
    }
}
相关问题