views:

510

answers:

4

Hi, When I try to find the value of BigInteger data type for 2 to power 23,000, I am not able to see the value. Upto 2 to power 22000, I could display the biginteger value . I am on XP. Any solution/suggestion? Sastry

+4  A: 

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?

Matthew Flaschen
+7  A: 

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.

coobird
A: 

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.

A: 

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.

Peter Lawrey