BigInteger如何存储其数据?

Jon*_*and 30 java biginteger

我一直在寻找相当长的一段时间,而且我几乎没有发现BigInteger它实际上如何保持它的数字.它们是一系列字符吗?别的什么?如何将数据转换为/从BigInteger

从我发现的,我假设所有任意精度类,如BigIntegerBigDecimal,将数据保存为字符数组.它是如何实际工作的?还是只是人们的猜测?

我问,因为我一直在努力实现自己的实现BigInteger,但我无法弄清楚如何保持数字大于Long.MAX_VALUE(我不记得实际的数字).

提前致谢.

cor*_*iKa 25

int[]

从来源:

/**
 * The magnitude of this BigInteger, in <i>big-endian</i> 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 ({@code 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.
 */
final int[] mag;
Run Code Online (Sandbox Code Playgroud)

  • 通俗地说......(在那个特定的实现中)*按位数字表示被打包成一个int数组*。 (3认同)
  • @glowcoder 感谢您的回复,但还有其他细节吗?例如它如何将输入转换为该数组? (2认同)
  • @TJ抱歉,我没有看到那里的点.:)我不想使用@Crowder,因为这恰好也是我经理的姓氏,我讨厌混淆两者(因为我喜欢你,我宁愿保持这种状态!)无论如何关于主题,我看了许可证,你是完全正确的.我删除了链接. (2认同)