What you want is BCD.
Binary-coded decimal - Wikipedia, the free encyclopedia[
^]
When viewed as hexadecimal, the decimal digit pair appear like decimal.
const char *text = "123456";
std::vector<unsigned char> number;
while (*text)
{
unsigned char pair = 0;
unsigned char digit = *text++;
digit -= '0';
pair = digit;
if (*text)
{
digit = *text++;
digit -= '0';
pair <<= 4;
pair |= digit;
}
number.push_back(pair);
}
for (int i = 0; i < number.size())
{
printf("%02X", number[i]);
}