/*
 * itoa \- converts an integer n to characters, represented in 
 *        base base.  Any base from 2-36 is legal.
 */

char *itoa(n, base)
long n;
short base;
{
	int i, j;
	long sign;
	static char s[100];

	if ((base < 2) || (base > 36))
		return(0);

	if ((sign = n) < 0)
		n = \-n;

	i = 0;
	do {
		if (base <= 10)
			s[i++] = n % base + '0';
		else {
			j = n % base;
			if (j < 10)
				s[i++] = j + '0';
			else
				s[i++] = (j\-10) + 'a';
		}
	} while ((n /= base) > 0);

	if (sign < 0)
		s[i++] = '\-';

	s[i] = '\0';

	reverse(s);

	return(s);
}
reverse(s)
char *s;
{
	int c, i, j;

	for (i=0, j = strlen(s)\-1; i < j; i++, j\-\-) {
		c = s[i];
		s[i] = s[j];
		s[j] = c;
	}
}
