Reputation: 988
i want to multiply two 512 bit integers in java and store the result.suggest some method to do this.
Upvotes: 8
Views: 2052
Reputation: 106351
Use java.math.BigInteger
A quick example of usage:
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));
}
}
Upvotes: 7