byte[] bytes = Files.readAllBytes(outFile.toPath());
Reserving the fully needed space ensures not using extra space, and no reallocations.
StringBuilder sb = new StringBuilder(bbytes.length * 2);
for (byte b : bytes) {
sb.append(String.format("%02X", b));
}
BigInteger dataInt = new BigInteger(sb.toString(), 16);
Then however it would be faster to do:
BigInteger dataInt = new BigInteger(1, bytes);
with the caveat, that this is a big endian interpretation. Reverting the bytes would be fast too however.
The actual algorithm unfortunately uses floating point, but that is your choice. You could look at the sources of their implementation of toString(radix).
Also BigInteger has some interesting methods, like modPow
or remainder
.
Whether or not the loops can be optimized, pow multiplied by base, or the loop entirely eliminated. that is something interesting I leave upto you.