Implementing unsigned itoa (uint to str)
This commit is contained in:
parent
1a9201b529
commit
5bfb8d9e97
2 changed files with 25 additions and 0 deletions
24
src/xtoa.c
24
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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue