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
19 extern void io_long(unsigned long);
20 extern void io_str(char *);
24 void ultoa(unsigned long value, __data unsigned char* str, unsigned char radix)
28 unsigned char buffer[NUMBER_OF_DIGITS]; /* space for NUMBER_OF_DIGITS + '\0' */
30 index = NUMBER_OF_DIGITS;
33 ch = '0' + (value % radix);
34 if ( ch > '9') ch += 'a' - '9' - 1;
39 io_long( (unsigned long) ch );
42 buffer[ --index ] = ch;
47 *str++ = buffer[index++];
48 } while ( index < NUMBER_OF_DIGITS );
50 *str = 0; /* string terminator */
53 void ltoa(long value, __data unsigned char* str, unsigned char radix)
57 io_long( (unsigned long)value );
60 if (value < 0 && radix == 10) {
67 ultoa((unsigned long)value, str, radix);