|
|
|
@ -6,7 +6,6 @@ char* itoa( int value, char * str, int base ) { |
|
|
|
|
char* ptr; |
|
|
|
|
char* low; |
|
|
|
|
|
|
|
|
|
// Check for supported base.
|
|
|
|
|
if( base < 2 || base > 36 ) { |
|
|
|
|
*str = '\0'; |
|
|
|
|
return str; |
|
|
|
@ -21,21 +20,16 @@ char* itoa( int value, char * str, int base ) { |
|
|
|
|
if(value < 0) |
|
|
|
|
*ptr++ = '-'; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Remember where the numbers start.
|
|
|
|
|
low = ptr; |
|
|
|
|
|
|
|
|
|
// The actual conversion.
|
|
|
|
|
do { |
|
|
|
|
// Modulo is negative for negative value. This trick makes abs() unnecessary.
|
|
|
|
|
*ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz"[35 + value % base]; |
|
|
|
|
value /= base; |
|
|
|
|
} while(value); |
|
|
|
|
|
|
|
|
|
// Terminating the string.
|
|
|
|
|
*ptr-- = '\0'; |
|
|
|
|
|
|
|
|
|
// Invert the numbers.
|
|
|
|
|
// Invert
|
|
|
|
|
while ( low < ptr ) { |
|
|
|
|
char tmp = *low; |
|
|
|
|
*low++ = *ptr; |
|
|
|
|