How are BigInteger stored

让人想犯罪 __ 提交于 2020-01-04 06:23:25

问题


I need to generate 512 bit BigInts, but I'm not sure which of the two below is true:

512 bits means 512 digits of 1010101010...001010 which are then converted to the decimal it represents?

Or does it mean 512 digits of 0-9, so basicly a 512-digit number with digits ranging from 0-9? Something like 12414124124....54543=512 digits.


回答1:


From sourcecode, they are stored in an int array

The magnitude of this BigInteger, in big-endian order: the zeroth element of this array is the most-significant int of the magnitude. The magnitude must be "minimal" in that the most-significant int (mag[0]) must be non-zero. This is necessary to ensure that there is exactly one representation for each BigInteger value. Note that this implies that the BigInteger zero has a zero-length mag array.

118 
119     int[] mag;
120 
121     // These "redundant fields" are initialized with recognizable nonsense
122     // values, and cached the first time they are needed (or never, if they
123     // aren't needed).
124 


来源:https://stackoverflow.com/questions/22779406/how-are-biginteger-stored

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!