10-11-2013 06:02 AM
Hi,
I hope you can help?
How to convert hex to Decimal and keep leading zeros
I read 002C, hex, and I want to convert it to 0044 decimal.
sscanf (MyNum, "%4x", &DecNum); will only give me 44.
It have been working up till I started to get leading zeros.
We will always have a 4 digit hex input in a range
We must have the leading 00 in this case.
How is this best done?
Thanks for the help
Simon
Solved! Go to Solution.
10-11-2013 07:43 AM
Hi,
I don't really understand your problem. Is this stuff what you need ?
int main (int argc, char *argv[])
{
const char MyNum[] = "002C";
int DecNum;
sscanf (MyNum, "%4x", &DecNum);
printf ("%04d", DecNum);
getchar ();
return 0;
}
"0044" appears on standard output when printf function executes...
10-11-2013 07:54 AM