#include #include static const char *numbers = "0123456789abcdef"; char * utoa(char *p, unsigned x, unsigned base) { p += 3 * sizeof(unsigned); *--p = '\0'; do { *--p = numbers[x % base]; x /= base; } while (x); return p; } char * itoa(char *p, int x, unsigned base) { const bool is_negative = (x < 0); if (is_negative) x = -x; p = utoa(p, (unsigned)x, base); if (is_negative) *--p = '-'; return p; }