简体   繁体   中英

Java BigInteger pow with BigInteger exponent

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)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM