Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
itoas.cpp
00001 #include "itoas.h" 00002 00003 char* ltoa( long value, char *string, int radix ) 00004 { 00005 char tmp[33]; 00006 char *tp = tmp; 00007 long i; 00008 unsigned long v; 00009 int sign; 00010 char *sp; 00011 if ( string == NULL ) 00012 { 00013 return 0 ; 00014 } 00015 if (radix > 36 || radix <= 1) 00016 { 00017 return 0 ; 00018 } 00019 sign = (radix == 10 && value < 0); 00020 if (sign) 00021 { 00022 v = -value; 00023 } 00024 else 00025 { 00026 v = (unsigned long)value; 00027 } 00028 while (v || tp == tmp) 00029 { 00030 i = v % radix; 00031 v = v / radix; 00032 if (i < 10) 00033 *tp++ = i+'0'; 00034 else 00035 *tp++ = i + 'a' - 10; 00036 } 00037 sp = string; 00038 if (sign) 00039 *sp++ = '-'; 00040 while (tp > tmp) 00041 *sp++ = *--tp; 00042 *sp = 0; 00043 return string; 00044 } 00045 00046 char* ultoa( unsigned long value, char *string, int radix ) 00047 { 00048 char tmp[33]; 00049 char *tp = tmp; 00050 long i; 00051 unsigned long v = value; 00052 char *sp; 00053 if ( string == NULL ) 00054 { 00055 return 0; 00056 } 00057 if (radix > 36 || radix <= 1) 00058 { 00059 return 0; 00060 } 00061 00062 while (v || tp == tmp) 00063 { 00064 i = v % radix; 00065 v = v / radix; 00066 if (i < 10) 00067 *tp++ = i+'0'; 00068 else 00069 *tp++ = i + 'a' - 10; 00070 } 00071 sp = string; 00072 00073 while (tp > tmp) 00074 *sp++ = *--tp; 00075 *sp = 0; 00076 return string; 00077 } 00078 00079 00080 char* itoa( int value, char *string, int radix ) 00081 { 00082 return ltoa( value, string, radix ) ; 00083 } 00084 00085 char* utoa( unsigned long value, char *string, int radix ) 00086 { 00087 return ultoa( value, string, radix ) ; 00088 }
Generated on Tue Jul 12 2022 18:59:49 by
1.7.2