Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hexadecimal to decimal conversion with sprintf in C

I have

sprintf(ascii,"%X",number) // number = 63 is a decimal integer`

char ascii[] = {51, 70, 0, 0, 0, .... } which displayed as "3F"

When I have

value = atoi(ascii);

It returns value = 3 not 63.

The thing that I want is hexadecimal conversion with sprintf, display it but then save the value inside the table as decimal to another variable.

How it can be done ?

like image 971
O.k Avatar asked Feb 09 '23 15:02

O.k


1 Answers

The problem is atoi doesn't parse hex. You need a function that parses a hex digit. sscanf(ascii, "%x", &i) comes to mind...

like image 71
kcraigie Avatar answered Feb 13 '23 04:02

kcraigie