Sastry
Sastry

Reputation:

Why is BIGInteger in JAVA not responding for higher powers?

When I try to find the value of a BigInteger data type for 223,000, I am not able to see the value.

However, for calculations up to 222,000, I could display the BigInteger value without any problems.

Is there any solution or reason for this?

Upvotes: 0

Views: 1665

Answers (4)

Peter Lawrey
Peter Lawrey

Reputation: 533820

this limit for BigInteger is around 2^16 billion, though it has been noted that some functions don't behave correctly after about 2^2 billion.

My guess is that your console or IDE has problems displaying very long lines.

Upvotes: 1

Mike H
Mike H

Reputation:

Do you need the whole thing? There is also a BigInteger.modpow(power, modulus) method which raises the integer value to the specified power and returning result % modulus -- commonly used in cryptography. This is also MUCH faster when dealing with very large exponents.

Upvotes: 0

coobird
coobird

Reputation: 161022

I tried the following in order to make a BigInteger representation of 2^23000:

BigInteger bi = new BigInteger("2");
bi = bi.pow(23000);
System.out.println(bi);

And the number displayed was a very large number spanning 6925 digits. (I won't paste it here as it will span over 100 lines.)

This is with Java 6 SE version 1.6.0_12 in Windows XP.

According the API Specification, BigInteger is an arbitrary-precision integer value which means it should be able to cope with very large integer values.

Upvotes: 8

Matthew Flaschen
Matthew Flaschen

Reputation: 285017

It works fine for me on GNU/Linux. What do you mean you can't "display" it? What's your code and what error/problem do you get?

Upvotes: 4

Related Questions