number base conversion? (ASCII to Hex)

Jeff Massung jmassung at magpiesystems.com
Thu May 11 18:09:37 EDT 2000


chibaA at TinterlogD.Tcom wrote in message
<391b2bd5.66612734 at news1.on.sympatico.ca>...
>How would I go about getting the base-16(hex) value of a character,
>into a string?
>

Why would you need to do this? The decimal and hexadecimal values are the
same. Just use itoa() on the decimal value (which is already the character
value). Perhaps I am misuderstanding the question?

>take character word[1] (for example)
>and retrieve the hex value of 31

31h = (16)*3+1 = 48+1 = 49

char *_itoa( int value, char *string, int radix );
/* The radix parameter is the base you want your string is: */

itoa(49,myString,2); /* myString = "110001" */
itoa(49,myString,10); /* myString = "49" */
itoa(49,myString,16); /* myString = "31" */

Make sense? Good luck!
Jeff





More information about the Python-list mailing list