A. *_*rge 5 c++ boost bit-manipulation biginteger data-conversion
我如何将 boost cpp_int(>1000 位)转换为字符串中的二进制表示形式(例如"1011....11001")?
我尝试过将其转换为std::bitset,但它不适用于更高的数字
编辑 - 解决方案:
这包含此问题的解决方案:
而不是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;
}
Run Code Online (Sandbox Code Playgroud)