Boost.Multiprecision cpp_int - 转换成字节数组? [英] Boost.Multiprecision cpp_int - convert into an array of bytes?

查看:529
本文介绍了Boost.Multiprecision cpp_int - 转换成字节数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://www.boost。 org / doc / libs / 1_53_0 / libs / multiprecision / doc / html / index.html

我刚开始探索这个库。似乎没有办法将 cpp_int 转换为字节数组。

I just started exploring this library. There doesn't seem to be a way to convert cpp_int into an array of bytes.

有人可以看到功能?

推荐答案

这是无记名的方式。 cpp_int 的后端有 limbs()成员函数。此函数返回内部字节数组值。

This is undocument way. cpp_int's backend have limbs() member function. This function return internal byte array value.

#include <iostream>
#include <boost/multiprecision/cpp_int.hpp>

namespace mp = boost::multiprecision;

int main()
{
    mp::cpp_int x("11111111112222222222333333333344444444445555555555");

    std::size_t size = x.backend().size();
    mp::limb_type* p = x.backend().limbs();

    for (std::size_t i = 0; i < size; ++i) {
        std::cout << *p << std::endl;
        ++p;
    }
}

结果:

10517083452262317283
8115000988553056298
32652620859

这篇关于Boost.Multiprecision cpp_int - 转换成字节数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆