BigInteger如何存储 [英] How are BigInteger stored

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

问题描述

我需要生成512位BigInts,但是我不确定下面两个中的哪一个是正确的:

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

512位表示1010101010...001010的512位数字,然后将其转换为它代表的小数?

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

或者它表示0-9的512位数字,所以从根本上讲是一个0到9范围内的512位数字?类似于12414124124 .... 54543 = 512位数字.

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.

推荐答案

从源代码开始,它们存储在int数组中

From sourcecode, they are stored in an int array

此BigInteger的大小,按大端顺序排列:此数组的第零个元素是该大小中最重要的int.幅度必须是最小"的,因为最重要的int(mag [0])必须不为零.必须确保每个BigInteger值都有一个唯一的表示形式.请注意,这意味着BigInteger零具有一个零长度的mag数组.

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 

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

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