I have two strings to add. Strings is HEX values. I convert strings to long long, add and after I back to string. But this operation no working good.
Code:
unsigned long long FirstNum = std::strtoull(FirstString.c_str(), NULL, 16);
unsigned long long SecondNum = std::strtoull(SecondString.c_str(), NULL, 16);
unsigned long long Num = FirstNum + SecondNum;
std::cout << " " << FirstNum << "\n+ " << SecondNum << "\n= " << Num << "\n\n";
I received
13285923899203179534
+ 8063907133566997305
= 2903086959060625223
Anyone can explain me this magic? How can I fix it?
Back to hex value by
std::stringstream Stream;
Stream << std::hex << Num;
return Stream.str();