Extracting bits from boost multiprecision

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.

Live On Coliru

#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, " "));


0xffffff61 0xffffffff 

Drop std::showbase to do without 0x. I picked this representation so it's maximally clear how the limbs are grouped.

You cannot have directly what you ask. Internal rapresentation is not necessarily done that way, one type uses even 'decimal' digits.

You can obtain that indirectly

uint256_t v = 0xffffffffffffffffffffffffffffff61;
std::ostringstream ost ;
ost << std::hex << v ; 

now ost.str() is FFFF....FFF61

Need Your Help

Twitter is scared of my lengthy url - gotta shorten it! [c#]

.net twitter url-shortener

I have a website where everytime one of our customers reviews a new product it gets tweeted onto the company twitter account automatically.

StandardJarScanner Error

spring jsp spring-mvc jstl

I have placed the spring-mvc jar files in the web-inf/lib folder and included jstl 1.2 in the lib folder. All the required jars are in the lib folder. For Spring.tld jar, I have checked in the stack