I have a number stored as a string up to 16 chars (0 to F) in length. This needs to be incremented and the result stored as a string.
Simplest thing would have been to convert the string to an int, increment by one, then convert back to a string. However the OS doesn’t support 64 numbers. What’s the alternative?
I presume a hand crafted solution using two 32 bit integers is possible, in which case this must be a common scenario, but I couldn’t find any boilerplate template code for doing such a thing after a bit of googling.
UPDATE: Sorry – sould have mentioned earlier – This is for Brew MP C++ – their conversion libraries’ APIs are limited to 32 bit.
And experimenting with long long seems to have fundamental big time problems in general executing on hardware, making it unusable.
You can increment one digit at a time. If the digit is between ‘0’ and ‘8’, just add one; likewise if it’s between ‘A’ and ‘E’. If it’s ‘9’, set it to ‘A’. If it’s ‘F’, set it to ‘0’ and increment the next digit to the left.