mirror of https://github.com/E-Almqvist/eOS
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
601 B
39 lines
601 B
#include "conv.h"
|
|
#include "../drivers/vga.h"
|
|
|
|
char* itoa( int value, char * str, int base ) {
|
|
char* rc;
|
|
char* ptr;
|
|
char* low;
|
|
|
|
if( base < 2 || base > 36 ) {
|
|
*str = '\0';
|
|
return str;
|
|
}
|
|
rc = ptr = str;
|
|
|
|
switch(base) {
|
|
case 16:
|
|
*ptr++ = '0';
|
|
*ptr++ = 'x';
|
|
case 10:
|
|
if(value < 0)
|
|
*ptr++ = '-';
|
|
}
|
|
low = ptr;
|
|
|
|
do {
|
|
*ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz"[35 + value % base];
|
|
value /= base;
|
|
} while(value);
|
|
|
|
*ptr-- = '\0';
|
|
|
|
// Invert
|
|
while ( low < ptr ) {
|
|
char tmp = *low;
|
|
*low++ = *ptr;
|
|
*ptr-- = tmp;
|
|
}
|
|
return rc;
|
|
}
|
|
|