I've pretty decent challenge. One of our systems works on huge numbers like uint256. Unfortunately, we receive such numbers as a string. In further calculations it's required to convert the numbers to their hexadecimal representations, and that's the problem.
What is the most efficient way to convert string with decimal integer representation to string with hex/binary representation?
We know the simplest solution is to use an external library e.g. boost and convert (decimal) string -> uin256 -> (hex) string, but we can't use any external library in this particular case.
To better understand the problem, we looking for a function toHex(...), such as:
void toHex(const char* decimal, char* result)
{
...
}
int main()
{
const char* decimal = "6322365123570985008687907853269984665640564039457584007913129639935";
char* hexadecimal;
toHex(decimal, hexadecimal);
printf("%s\n", hexadecimal);
return 0;
}
output
3C08D179C2394472E8C2036E13A5F862C7EEE1D4E7FFFFFFFFFFFFFF
P.S.
The numbers are always positive, so we don't have to care about the sign.