1 /*-------------------------------------------------------------------------
2 integer to string conversion
4 Written by: Bela Torok, 1999
8 _ultoa(unsigned long value, char* string, int radix)
9 _ltoa(long 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 32
18 void _ultoa(unsigned long value, char* string, unsigned char radix)
21 char buffer[NUMBER_OF_DIGITS]; /* space for NUMBER_OF_DIGITS + '\0' */
23 index = NUMBER_OF_DIGITS;
26 buffer[--index] = '0' + (value % radix);
27 if ( buffer[index] > '9') buffer[index] += 'A' - '9' - 1;
32 *string++ = buffer[index++];
33 } while ( index < NUMBER_OF_DIGITS );
35 *string = 0; /* string terminator */
38 void _ltoa(long value, char* string, unsigned char radix)
40 if (value < 0 && radix == 10) {
42 _ultoa(-value, string, radix);
45 _ultoa(value, string, radix);