diff --git a/src/xtoa.c b/src/xtoa.c index 3cf1990..aaf7b69 100644 --- a/src/xtoa.c +++ b/src/xtoa.c @@ -24,6 +24,30 @@ char* itoa(int value, int base) { } return result; } +char* uitoa(unsigned int value, int base) { + char* result; + + // check that the base if valid + if (base < 2 || base > 36) { *result = '\0'; return result; } + + char* ptr = result, *ptr1 = result, tmp_char; + int tmp_value; + + do { + tmp_value = value; + value /= base; + *ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz" [35 + (tmp_value - value * base)]; + } while ( value ); + + + *ptr-- = '\0'; + while(ptr1 < ptr) { + tmp_char = *ptr; + *ptr--= *ptr1; + *ptr1++ = tmp_char; + } + return result; +} char* ltoa(long value, int base) { char* result; diff --git a/src/xtoa.h b/src/xtoa.h index 80445fa..710c774 100644 --- a/src/xtoa.h +++ b/src/xtoa.h @@ -2,6 +2,7 @@ #define HEADER_XTOA char* itoa(int value, int base); +char* uitoa(unsigned int value, int base); char* ltoa(long value, int base); char* ultoa(unsigned long value, int base);