forked from PoliEcho-holding-org/kern
Added string.h header with itoa function that converts an int to a ASCII string
This commit is contained in:
@@ -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];
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
#ifndef STRING_H
|
||||||
|
#define STRING_H
|
||||||
|
|
||||||
|
#include "stdint.h"
|
||||||
|
|
||||||
|
char* itoa(uint32_t val, uint8_t base);
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user