How to make a BigInteger that is 10^3 bits large in Java? [duplicate]
How to make a BigInteger that is 10^3 bits large in Java? [duplicate]
This question already has an answer here:
I was wondering how to make a BigInteger of size 10^3 bits in length which is being the max value of the said length.
It would be similar to the question posted here...
How to create BigInteger of 256 bits with all bits set
except on an even larger scale.
Thanks!
edit:This is what I have at the moment:
for(int i = 3; i<= 8; i++){
for(int j = 0; j < 99; j++){
//Creates a Positive BigInteger of 10^i in bit size filled with ones
byte b = new byte[(10^i) / 8 + 1];
Arrays.fill(b, (byte) 127);
b[0] = 0;
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Same as the other question! For BigInteger is the same, just use 1000 instead.
– niqueco
Sep 16 '18 at 22:08
@ricky3350 Thanks for the quick response! Added more to the description
– Kezz
Sep 16 '18 at 22:10
Take the accepted answer to the question that you linked, and replace 256 with 1000.
– Erwin Bolwidt
Sep 16 '18 at 22:24
The
^
operator in Java is exclusive-or, not to-power. For values up to about 53 bits you can use (int) Math.pow(10,i)
.-- and Java doesn't allow array sizes more than 2^31-1 anyway.– dave_thompson_085
Sep 16 '18 at 23:25
^
(int) Math.pow(10,i)
1 Answer
1
Biginteger does not have a said or constant limit. It is dynamically allocated. You must make your own implementation that makes sure your said value is the limit, if that is what you want.
You might actually want to consult the constructors to see what fits for your code.
Have you tried the solution in the question you linked? If so, why didn't it work?
– ricky3350
Sep 16 '18 at 22:07