how to print boost multiprecision 128 bit unsigned integer

0

I want to print integer value that converted from hexadecimal value but i only could print hexadecimal value.

#include <iostream>
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;

    cpp_int          dsa("0xFFFFFFFFFFFFFFFF");
    cpp_int          daa("9223372036854775807");
    daa = ((daa * 64) + daa);
    cout << std::hex<<dsa <<std::showbase<< endl;
    cout <<dsa << endl;
    cout <<daa << endl;
    cout <<(int)daa << endl;
    cout <<(int128_t)daa << endl;

output

ffffffffffffffff
0xffffffffffffffff
0x207fffffffffffffbf
0x7fffffff
0x207fffffffffffffbf

How can i print max value of 128 bit type of integer ?

c++
boost
boost-multiprecision
asked on Stack Overflow Feb 17, 2020 by Serhan Erkovan

1 Answer

3

You should use std::numeric_limits to get the max value, because that's its purpose. Your formatting issue is independent of your actual question.

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

int main()
{
    auto max = std::numeric_limits<boost::multiprecision::int128_t>::max();
    std::cout << max << std::endl;
}
answered on Stack Overflow Feb 17, 2020 by lars • edited Feb 17, 2020 by Toby Speight

User contributions licensed under CC BY-SA 3.0