diff --git a/src/kernel/string.c b/src/kernel/string.c new file mode 100644 index 0000000..740dc2b --- /dev/null +++ b/src/kernel/string.c @@ -0,0 +1,18 @@ +#include "string.h" + +char* itoa(uint32_t val, uint8_t base) { + static char buf[32] = { 0 }; + + if (base == 0 || base > 16) { + // TODO: Add errors!! + return buf; + } + + int i = 30; + for (; val && i; i--, val /= base) { + buf[i] = "0123456789abcdef"[val % base]; + } + + return &buf[i + 1]; +} + diff --git a/src/kernel/string.h b/src/kernel/string.h new file mode 100644 index 0000000..8e02a23 --- /dev/null +++ b/src/kernel/string.h @@ -0,0 +1,8 @@ +#ifndef STRING_H +#define STRING_H + +#include "stdint.h" + +char* itoa(uint32_t val, uint8_t base); + +#endif