1 /*- 2 * Copyright (c) 1982, 1986 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * @(#)printn.c 7.3 (Berkeley) 05/03/91 8 */ 9 10 #include "sys/param.h" 11 12 /* 13 * Printn prints a number n in base b. 14 * We don't use recursion to avoid deep kernel stacks. 15 */ 16 printn(n, b) 17 u_long n; 18 int b; 19 { 20 register char *cp; 21 char prbuf[11]; 22 23 if (b == 10 && (int)n < 0) { 24 putchar('-'); 25 n = (unsigned)(-(int)n); 26 } 27 cp = prbuf; 28 do { 29 *cp++ = "0123456789abcdef"[n%b]; 30 n /= b; 31 } while (n); 32 do 33 putchar(*--cp); 34 while (cp > prbuf); 35 } 36