OVH Cloud OVH Cloud

Translate decimal in string to heaxdecimal in string

1 réponse
Avatar
loic.bourgeois
Hello,

I would like Translate decimal string ("123456789") from a string to
hexadecimal in string ("75BCD15") without use strtol or strtoul or
some thing like that. The reason is the decimal number can be very
very long.


example to update:
char dec[]="123456789";
char hexa[];

sprintf(hexa, "%lX", strtoul(dec,10)); ==> This is to dangerouse,
because the value can be very hight.

printf("%s", hexa);


Thanks to help me

1 réponse

Avatar
Emmanuel Delahaye
In 'fr.comp.lang.c', (loic) wrote:

Hello,


Why in the world do you post in English to a French speaking newsgroup?

I would like Translate decimal string ("123456789") from a string to


'to translate' or 'to convert'

hexadecimal in string ("75BCD15") without use strtol or strtoul or
some thing like that. The reason is the decimal number can be very


'something'

very long.


example to update:
char dec[]="123456789";
char hexa[];

sprintf(hexa, "%lX", strtoul(dec,10)); ==> This is to dangerouse,


'dangerous'

because the value can be very hight.


'high'

Quelle valeur max ? "%lX" permet de 0 à 4294967295. C'est pas assez? Essayer
C99 qui permet les long long (64 bits) avec strtoull().

printf("%s", hexa);


--
-ed- [remove YOURBRA before answering me]
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
<blank line>
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/