BigInteger如何存储其数据? [英] How does BigInteger store its data?

查看:92
本文介绍了BigInteger如何存储其数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've been searching around for quite a while, and I've found almost nothing on how BigInteger actually holds its numbers. Are they an array of chars? Something else? And how is data converted to/from BigInteger?

从我发现的,我假设所有任意精度类,如 BigInteger BigDecimal ,将数据保存为字符数组。这是它的实际工作方式吗?或者这只是人们的猜测?

From what I've found, I am assuming that all of arbitrary precision classes, like BigInteger and BigDecimal, hold data as a character array. Is this how it actually works? Or is it just people's guess?

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

I'm asking because I have been working on my own implementation of something like BigInteger, but I can't figure out how to hold numbers larger than Long.MAX_VALUE (I don't remember the actual number).

提前致谢。

推荐答案

使用 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;

这篇关于BigInteger如何存储其数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆