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 ?

Serhan Erkovan
  • 481
  • 4
  • 18

1 Answers1

2

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;
}
Toby Speight
  • 27,591
  • 48
  • 66
  • 103
lars
  • 475
  • 2
  • 6
  • it says ```expected an identifier ``` about ```max()``` @lars – Serhan Erkovan Feb 17 '20 at 14:21
  • Then you did something wrong or use an old compiler. Here you can check, that the example compiles. https://godbolt.org/z/vHxGfZ – lars Feb 17 '20 at 15:02
  • I use microsoft compiler maybe it could be a problem @lars – Serhan Erkovan Feb 17 '20 at 15:05
  • Copy the exact error message and compiler version. Otherwise no one will be able to help u – lars Feb 17 '20 at 15:06
  • 1
    You needed std::dec only because you used std::hex previously. std::cout is stateful. So your issue was actually not what you asked for ;) "How can i print max value of 128 bit type of integer ?" But you should really use numeric_limits to get the max value, because that's its purpose. – lars Feb 17 '20 at 15:08
  • 2
    "But you should really use numeric_limits to get the max value, because that's its purpose." should be part of the answer. In my opinion it therefore ins not self explaining. –  Feb 17 '20 at 15:27