1 /*-------------------------------------------------------------------------
2 integer to string conversion
4 Written by: Bela Torok, 1999
8 uitoa(unsigned int value, char* string, int radix)
9 itoa(int value, char* string, int radix)
11 value -> Number to be converted
13 radix -> Base of value (e.g.: 2 for binary, 10 for decimal, 16 for hex)
14 ---------------------------------------------------------------------------*/
16 #define NUMBER_OF_DIGITS 16 /* space for NUMBER_OF_DIGITS + '\0' */
18 void uitoa(unsigned int value, char* string, int radix)
20 unsigned char index, i;
22 index = NUMBER_OF_DIGITS;
26 string[--index] = '0' + (value % radix);
27 if ( string[index] > '9') string[index] += 'A' - ':'; /* continue with A, B,.. */
32 string[i++] = string[index++];
33 } while ( index < NUMBER_OF_DIGITS );
35 string[i] = 0; /* string terminator */
38 void itoa(int value, char* string, int radix)
40 if (value < 0 && radix == 10) {
42 uitoa(-value, string, radix);
45 uitoa(value, string, radix);