2 * (c) Copyright 1990 Conor P. Cahill (uunet!virtech!cpcahil).
3 * You may copy, distribute, and use this software as long as this
4 * copyright statement is not removed.
11 * Purpose: to convert an integer to an ascii display string
13 * Arguments: buf - place to put the
14 * val - integer to convert
15 * len - length of output field (0 if just enough to hold data)
16 * base - base for number conversion (only works for base <= 16)
17 * fill - fill char when len > # digits
19 * Returns: length of string
21 * Narrative: IF fill character is non-blank
24 * add "0x" to begining of string
26 * add "0" to begining of string
28 * While value is greater than zero
29 * use val % base as index into xlation str to get cur char
32 * Determine fill-in length
40 * 90/01/24 cpcahil Initial revision.
45 char rcs_hdr
[] = "$Id: tostring.c,v 1.2 2006-07-25 10:10:17 rt Exp $";
51 tostring(buf
,val
,len
,base
,fill
)
59 char * bufstart
= buf
;
61 char * xbuf
= "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
65 * if we are filling with non-blanks, make sure the
66 * proper start string is added
94 tbuf
[--i
] = xbuf
[val
% base
];
112 * string is too long so we must truncate
113 * off some characters. We do this the easiest
114 * way by just incrementing i. This means the
115 * most significant digits are lost.
126 *(buf
++) = tbuf
[i
++];
129 return( (int) (buf
- bufstart
) );