From: bela Date: Mon, 12 Aug 2002 14:09:57 +0000 (+0000) Subject: added functions _ltoa _uitoa X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=ed14a50cf2be75a6bbd0af822d763cadc5325a20;p=fw%2Fsdcc added functions _ltoa _uitoa git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2074 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/device/lib/_ltoa.c b/device/lib/_ltoa.c new file mode 100755 index 00000000..0ba0c3db --- /dev/null +++ b/device/lib/_ltoa.c @@ -0,0 +1,48 @@ +/*------------------------------------------------------------------------- + integer to string conversion + + Written by: Bela Torok, 1999 + bela.torok@kssg.ch + usage: + + _ultoa(unsigned long value, char* string, int radix) + _ltoa(long value, char* string, int radix) + + value -> Number to be converted + string -> Result + radix -> Base of value (e.g.: 2 for binary, 10 for decimal, 16 for hex) +---------------------------------------------------------------------------*/ + +#define NUMBER_OF_DIGITS 32 + +void _ultoa(unsigned long value, char* string, unsigned char radix) +{ +unsigned char index; +char buffer[NUMBER_OF_DIGITS]; /* space for NUMBER_OF_DIGITS + '\0' */ + + index = NUMBER_OF_DIGITS; + + do { + buffer[--index] = '0' + (value % radix); + if ( buffer[index] > '9') buffer[index] += 'A' - '9' - 1; + value /= radix; + } while (value != 0); + + do { + *string++ = buffer[index++]; + } while ( index < NUMBER_OF_DIGITS ); + + *string = 0; /* string terminator */ +} + +void _ltoa(long value, char* string, unsigned char radix) +{ + if (value < 0 && radix == 10) { + *string++ = '-'; + _ultoa(-value, string, radix); + } + else { + _ultoa(value, string, radix); + } +} + diff --git a/device/lib/libsdcc.lib b/device/lib/libsdcc.lib index 25246d10..7f3978c1 100644 --- a/device/lib/libsdcc.lib +++ b/device/lib/libsdcc.lib @@ -7,6 +7,8 @@ _ispunct _isspace _isupper _isxdigit +_itoa +_ltoa _strchr _strcmp _strcpy