【发布时间】:2017-02-23 13:13:43
【问题描述】:
在Java中,有一个BigInteger类来使用大数,它有一个转换函数:toByteInteger,像这样:
private static final BigInteger N = new BigInteger(HEX_N, 16);
...
byte[] digest = messageDigest.digest(N.toByteArray());
在 C++ 中,我尝试Boost.Multiprecision 使用带有 mpz_int 的大数类型,但它没有任何将 mpz_int 转换为 字节数组。
C++ 中是否有任何等效的 BigInteger 类型?我正在使用 qt 框架,qt 上是否有任何大整数结构?是否可以将其转换为字节数组?
【问题讨论】:
-
将其内部值的引用转换为
char*或void*怎么样?不会是你的字节数组吗? -
在docs 中我找到了
convert_to<>。你试过了吗? -
或 v.backend().data().mpz_export(...),参见:boost.org/doc/libs/1_63_0/libs/multiprecision/doc/html/… 和 gmplib.org/manual/…
-
@tobi303 首先,我将 mpz_int 转换为 std::string,而不是使用 string 的 c_str() 方法。谢谢。
标签: c++ arrays qt boost boost-multiprecision