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;
}