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.






Have you tried the solution in the question you linked? If so, why didn't it work?

– ricky3350
Sep 16 '18 at 22:07






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.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)