1

Hi i want to calculate

2^(256bit number)

in java, but biginteger's pow function just can handle ints.

How can i calculate with larger numbers?

Is there any library?

i want to calculate all numbers from

2^0
2^1
2^2
...
2^(10^77)
4
  • You can always use more pows... (if not for the bit shift). Curious however: Why? Commented Sep 8, 2013 at 20:19
  • possible duplicate of Very Large Numbers in Java Without using java.math.BigInteger Commented Sep 8, 2013 at 20:20
  • For this particular case you can use shiftLeft, but it is a weird oversight. Commented Sep 8, 2013 at 20:20
  • Just write a 1 and put number times 0 to get the binary representation, it can't be hard to get this into whatever other form you need? Commented Sep 8, 2013 at 20:20

1 Answer 1

4

I suspect the reason they didn't bother including anything like this is that in most cases, the number would be too big to represent.

Consider 2^(256 bit number). The result has (256bit number) bits, meaning that it takes more memory then there are particles in the universe.

So you'll have to find a different way to represent your logic. Perhaps you could do it symbolically.

It would be possible to do 2^(2^32) and exponents close to that, but this was probably seen as a niche case that they just didn't bother adding a function for.

Sign up to request clarification or add additional context in comments.

11 Comments

I've been wondering also... According to this: "The number of atoms in the entire observable universe is estimated to be within the range of 10^78 to 10^82."
2^256 just happens to be 10^77, so I was actually closer then I thought. Anyway, it's just a rough comparison. The point is that it's bigger then you could ever reasonably compute.
I didn't write to disagree, or pick nits, I'd totally consider numbers of this magnitue useless for just about anything... Frankly, I can not think of any practical use...
There isn't a practical use for numbers above 10^100 IMHO. And in the real world you can't measure many constants better than to 13 digits. So really a double is all you need in the real world. ;)
@wutzebaer 256 is not a 256 bit number, it is a 8 bit number. We are speaking of numbers that have 2^256 or 10^77 as exponent.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.