从boost多precision提取位 [英] Extracting bits from boost multiprecision
问题描述
我使用uint256_t使对大整数运算;我想,因为我只使用整数和不浮点数没有任何precision提取数的各位以规则形式(即不以浮点形式)。
例如:
如果我的code的:
的#include<升压/多precision / cpp_int.hpp>
uint256_t V = 0xffffffffffffffffffffffffffffff61;
然后我想有32个字节:
61 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
您也许能够直接使用的后端再presentation。
检查文档,这是否是公共的API的一部分。
<大骨节病> 住在Coliru 骨节病>
的#include&LT;升压/多precision / cpp_int.hpp&GT;
#包括LT&;&iostream的GT;诠释主(){
使用空间boost ::多precision;
uint256_t V(0xffffffffffffffffffffffffffffff61); 的std :: copy_n(v.backend()。肢(),v.backend()。大小()
的std :: ostream_iterator&LT;无符号&GT;(STD ::法院LT&;&LT;的std ::六角&LT;&LT;的std :: showbase,));
}
打印
0xffffff61为0xffffffff
丢弃的std :: showbase
没有 0X
做的。我拿起这个重presentation所以它的最大清楚如何肢体
s的分组。
I'm using uint256_t to make arithmetic operation on big integers; I would like to extract the bits of the numbers in a regular form, (i.e. not in a floating point form) without any precision since I'm only using integers and not floats.
For example: if my code has:
#include <boost/multiprecision/cpp_int.hpp>
uint256_t v = 0xffffffffffffffffffffffffffffff61;
Then I would like to have 32 bytes:
61 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
You might be able to use the backend representation directly.
Check the documentation whether this is part of the public API.
#include <boost/multiprecision/cpp_int.hpp>
#include <iostream>
int main() {
using namespace boost::multiprecision;
uint256_t v("0xffffffffffffffffffffffffffffff61");
std::copy_n(v.backend().limbs(), v.backend().size(),
std::ostream_iterator<unsigned>(std::cout << std::hex << std::showbase, " "));
}
Prints
0xffffff61 0xffffffff
Drop std::showbase
to do without 0x
. I picked this representation so it's maximally clear how the limb
s are grouped.
这篇关于从boost多precision提取位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!