Boost Multiprecision understands hexadecimal strings without need for help:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <boost/multiprecision/cpp_int.hpp>
#include <iostream>
#include <string>
using integer = boost::multiprecision::cpp_int;
int main()
{
const std::string s = "cf91cc61b74a1feda9902ae9b9e96d9a";
integer n = integer( "0x" + s );
std::cout << "s (hex) = " << s << "\n";
std::cout << "n (dec) = " << std::dec << n << "\n";
std::cout << "n (hex) = " << std::hex << n << "\n";
}
@JLBorges
I’m not convinced that testing the Arabic digits separately has much advantage compared to just putting them in the lookup string... but even so, I honestly don’t know of any hardware where A..F and a..f are not consecutively sequential.
you would have to rewrite it a little. Somewhere in there it cooks up the hex digits, and you place them into the big int instead of a string. It may not be worth it, but text to number and number to text are expensive if not necessary. If you need both a string and the value, it won't help. It only helps if you need the value, and not the string. If what you have is working, and fast enough, may also not be worth it.
You do not need to compile Boost Libraries to use the Boost cpp_int type.
A bignum integer behaves just like a machine integer at your level of abstraction, so yes, you can use all the usual arithmetic operations on it, and overloads of most of the math functions too.