Question about programming (a little off-topic)
DAVIDSANAN
DAVIDSANAN at teleline.es
Mon Dec 16 19:49:33 EST 2002
Hi Juan Luis. I don't know if there is something to do it directly but
you can convert from hexadecimal to decimal with a little function that
do the following: 16*hn + ln (where hn is the high nibble and ln is the
low nibble). So for C0 you'll do 16*C(12)+0=192.
To transform from letter to number you can do: int(ch)-int('A')+10 (if
the ch is in uppercase).
In c++ you can implement the following:
(note that if you declare 'dec' as int dec[4]; you can't get more than
4 digits)
void converthtd(char *hex,int *dec){
int conth,contd;
int decimal;
int mult;
mult=1;
contd=-1;
for (conth=0;hex[conth];conth++){
if (hex[conth]!=':'){
if (mult==16) mult=1;
else{
mult=16;
contd++;
dec[contd]=0;
}
if (hex[conth]>'9') dec[contd]=dec[contd]+(int(hex[conth])-int
('A'))*mult;
else dec[contd]=dec[contd]+(int(hex[conth])-int('0'))
*mult;
}
}
}
More information about the click
mailing list