我将负号值导出到位并导回,但是当位导入符号丢失时。
typedef multiprecision::int512_t balance_value;
vector<uint8_t> byteSet;
export_bits(static_cast<boost::multiprecision::int512_t>(balance), back_inserter(byteSet), 8);
当我尝试将位导入回 int512_t 时,值的符号丢失了。
balance_value balance;
import_bits(balance, byteSet.begin(), byteSet.end());
最佳答案
这是设计使然。 documentation州
Exports the absolute value of val to
OutputIterator out
. The function will writechunk_size
bits at a time to theOutputIterator
, and ifmsv_first
is true, will write the most-significant block first. Byte and bit order within eachchunk_size
block is always in the machines native format. Further, each block is stored in aboost::uintmax_t
when it's assigned to*out
.
如果您需要可移植的表示形式,还要注意字节顺序问题。
关于c++ - 将 cpp_int 类型导出到位时,boost::multiprecision::export_bits 丢失符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40653907/