CONVERTIR EN HEXADECIMAL

cs_Matheus Messages postés 2 Date d'inscription dimanche 5 janvier 2003 Statut Membre Dernière intervention 19 avril 2004 - 12 juil. 2003 à 00:39
sebseb42 Messages postés 495 Date d'inscription dimanche 6 juillet 2003 Statut Membre Dernière intervention 9 novembre 2007 - 13 juil. 2003 à 05:13
Bonjour !!!

Je voulais savoir s'il existait une fonction contenue dans une librairie du C++ pour convertir des nombres d'une base à une autre, comme du décimal en hexadécimal.

Merci

M@théus

2 réponses

BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019
12 juil. 2003 à 01:17
bin vers base x, tu as itoa() et ultoa.
Le reste on l'ecrit.
BruNews, ciao...
0
sebseb42 Messages postés 495 Date d'inscription dimanche 6 juillet 2003 Statut Membre Dernière intervention 9 novembre 2007 1
13 juil. 2003 à 05:13
genre ca :

int get_val_from_digit(char c, char *hex_buff)
{
if ((c < '0' || c > '9') &&
(c < 'A' || c > 'Z') &&
(c < 'a' || c > 'z'))
{
fprintf(stderr, "invalid hexadecimal value : %s\n", hex_buff);
exit(0);
}
if (c >= '0' && c <= '9')
return (c - '0');
else
{
if (c >= 'a' && c <= 'z')
c -= 32;
return (c - 'A' + 10);
}
}

int hex_to_asc(char *hex_buff)
{
int c;
int i, k;
int val;

val = 0;
k = (int)strlen(hex_buff) - 1;
for (i = 0; hex_buff[i]; i++)
{
c = get_val_from_digit(hex_buff[i], hex_buff);
val += (c * (1 << (4 * (k - i))));
}
return (val);
}

:)
0
Rejoignez-nous