以 10 为基数打印以 4294967296 为基数的整数
我在 C++ 中有一个 32 位整数向量(可变大小,连续内存;就像 C 数组),代表基数 4294967296 中的数字。我想以基数 10 打印它。
这些数字可能非常大并接管几兆字节的内存。
就性能而言,最好的方法是什么?我可以使用 GMP 来做到这一点吗?
I have in C++ a vector of 32 bits integers (variable size, continous memory; like a C-array), representing a number in base 4294967296. I would like to print it in base 10.
These numbers can be extremely big and take over a few megabytes of memory.
What would be the best way to do this in terms of performance? Can I use GMP to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您可以为此使用 GMP。您要查找的函数是
mpn_get_str
:http://gmplib.org/manual/Low_002dlevel-Functions.html#Low_002dlevel-Functions
现在唯一的问题是
mp_limb_t
的大小。它可以是 32 位整数,也可以是 64 位整数,具体取决于平台。mpn_get_str
。或者,使用 mpz 整数类可能更容易。 导入你的整数数组到一个大的整数,然后 打印 将其返回基地10。
Yes, you can use GMP for this. The function that you're looking for is
mpn_get_str
:http://gmplib.org/manual/Low_002dlevel-Functions.html#Low_002dlevel-Functions
Now the only issue is the size of
mp_limb_t
. It is either a 32-bit integer or a 64-bit integer depending on the platform.mpn_get_str
.Alternatively, it might be easier to use the
mpz
integer class. Import your integer array into a large integer, then print it back out in base 10.