Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在c上使用GMP,我有一个十进制形式的大整数“mpz_t n”,我怎样才能把它分成两部分?实际上,这两个部分在二进制中应该具有相同的长度。
例如,也许我可以将 n 转换为 112 位的二进制,然后我想将其切割成 2 个 56 位的部分。
谢谢
我会使用 temp = mpz_sizeinbase(n,2) 来获取原始数字中的位数,然后使用 mpz_tdiv_q_2exp(q, n, temp>>1) 和 mpz_tdiv_r_2exp(r, n, temp>>1) 来获得原始数字的上半部分和下半部分。
根据您要如何处理奇数位长度,您可能需要调整 temp>>1 的计算。
HTH, casevh