将任意大小的字符串转换为任意精度的整数(bigint)
我正在尝试对任意大整数实施 Solovoy-Strassen 素性测试。我还将编写一个 bignum (不能使用第三方实现,因为这是一个学术项目)。我已经决定使用以下 bignum 结构:
struct {
uint64_t *tab;
int size; // number of limbs
int sign;
}
我将使用 base-32 作为我的数字(因此 uint64_t,对于部分产品,至少我假设它们将是部分产品)。此决定基于上一个问题问。
我处于停滞状态。我无法想象如何将一个表示为任意大小的小数的字符串并将其转换为上面的 bignum 结构。
有人可以请启发我吗?即使是一个较小的示例也很好,例如将任意字符串转换为八进制数字,并将其存储在 uint16_t 数组中。
谢谢。
I'm trying to implement the Solovoy-Strassen primality test for arbritrary large integers. I will also be writing a bignum (cannot use 3rd party implementation as this is an academic project). I have decided on the following structure for the bignum:
struct {
uint64_t *tab;
int size; // number of limbs
int sign;
}
I will be using base-32 for my digits (hence uint64_t, for partial products, at least I assume they will be partial products). This decision was based on a previous question asked.
I'm at a standstill. I cannot conceive how one can take a string represented as an arbitrary size decimal and convert it into the bignum structure above.
Could someone please enlighten me. Even a smaller example would be nice, such as converting maybe an arbitrary string into octal digits which would be stored in a uint16_t array.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要进行算术,调用您的例程。例如,如果字符串是“2013”(表示十进制的 2013),则执行:
a=0; a=10*a+2; a=10*a+0; a=10*a+1; a=10*a+3
。You need to do the arithmetic, calling your routines. For example, if the string is "2013" (representing 2013 in decimal), do:
a=0; a=10*a+2; a=10*a+0; a=10*a+1; a=10*a+3
.