5

How can i convert boost cpp_int (>1000 bits) to it's binary representation in string (e.g. "1011....11001") ?

I have tried convert it by std::bitset, but it does not work on higher numbers

Edit - solution:
This contains a solution for this question:
Instead of int -> cpp_int

std::string toBinary(boost::multiprecision::cpp_int n)
{
    std::string r;
    while(n != 0)
    {
        r = (n % 2 == 0 ? "0":"1") + r;
        n /= 2;
    }
    return r;
}
Mat3o
  • 5
  • 1
  • 4
A. George
  • 81
  • 4
  • 2
    Welcome ! You question seems interesting. However, can you show what you've tried and what higher numbers don't work ? – Christophe Oct 29 '18 at 07:42
  • 1
    Have a look at this: https://www.boost.org/doc/libs/1_68_0/libs/multiprecision/doc/html/boost_multiprecision/tut/import_export.html – Sebastian Schmitz Oct 29 '18 at 08:21

0 Answers0