Java’s BigInteger implementation

Java’s BigInteger implementation … here is a solution to the problem.

Java’s BigInteger implementation

I’m new here, so please forgive my rookie mistake. I’m currently working on my little project that lets me work with numbers that are forty thousand and above in length.

I’m currently using BigInteger to handle these values, and I need something faster to execute. I’ve read that BigInteger uses an array of integers in its implementation, and all I need to know is whether BigInteger uses every index in this array to represent every decimal point, like 1 – 9, or if it uses something more efficient

I

ask this because I’ve thought of an implementation that uses bit manipulation, which makes it more efficient in terms of memory and processing.

So the last question is – is BigInteger already efficient enough that I should just rely on it? It is better to know this than to test unnecessarily, which will take a lot of time.

Thank you.

Solution

At least for Oracle’s Java 8 and OpenJDK 8, it does not store one decimal place for each int. It stores the full 32-bit part for each 32-bit int in int[], which can be done by the relevant BigInteger Bitwise methods instead of implementing your own.

If you still need more speed, try something like GMP, but note that it uses an LGPL or GPL license. It would also be better to use it outside of Java.

Related Problems and Solutions