/* XXX: caller MUST check base is 2 .. 16 */
void radix_print(unsigned int n, int base)
{
  if (n >= base) radix_print(n / base, base);
  putchar("0123456789ABCDEF"[n % base]);
}

void swap_char_at(char *s, char *t)
{
  char c;

  c = *t;
  *t = *s;
  *s = c;
}

/* sprintf-like version of radix_print */
void radix_sprint(char *s, unsigned int n, int base)
{
  char *h = s;

  do {
    *s++ = "0123456789ABCDEF"[n % base];
    n /= base;
  } while (n > 0);

  *s-- = '\0';  /* terminate string and point
                   back at the last char of the string. */

  /* reverse string */
  while (h < s){
    swap_char_at(h++, s--);
  }
}