1 /* $Id: radix32.c 6118 2003-01-13 06:44:24Z rra $
3 ** Radix-32 strings divide a number into five-bit nibbles and use the
4 ** alphabet 0..9a..v to represent 0..32.
14 static char ALPHABET[] =
15 "0123456789abcdefghijklmnopqrstuv";
19 ** Turn a number into a Radix-32 string. Assume the number fits into
22 void Radix32(unsigned long l, char *buff)
28 /* Simple sanity checks. */
29 if ((l &= 0xFFFFFFFFL) == 0) {
30 *buff++ = ALPHABET[0];
35 /* Format the string, in reverse. */
36 for (p = temp; l; l >>= 5)
37 *p++ = ALPHABET[(int)(l & 037)];
40 for (i = p - temp; --i >= 0; )
48 ** Return a Radix-32 string as a number, or ~0 on error.
57 for (l = 0; *p; p++) {
58 if ((cp = strchr(ALPHABET, *p)) == NULL)
60 l = (l << 6) + cp - ALPHABET;