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