]> www.ginac.de Git - cln.git/blob - src/base/output/cl_output_hex.cc
* All Files have been modified for inclusion of namespace cln;
[cln.git] / src / base / output / cl_output_hex.cc
1 // fprinthexadecimal().
2
3 // General includes.
4 #include "cl_sysdep.h"
5
6 // Specification.
7 #include "cln/io.h"
8
9
10 // Implementation.
11
12 namespace cln {
13
14 void fprinthexadecimal (cl_ostream stream, unsigned long x)
15 {
16         #define bufsize 16
17         var char buf[bufsize+1];
18         var char* bufptr = &buf[bufsize];
19         *bufptr = '\0';
20         do {
21                 unsigned long q = x / 16;
22                 unsigned long r = x % 16;
23                 *--bufptr = (r<10 ? '0'+r : 'A'-10+r);
24                 x = q;
25         } while (x > 0);
26         fprint(stream,bufptr);
27         #undef bufsize
28 }
29
30 void fprinthexadecimal (cl_ostream stream, long x)
31 {
32         if (x >= 0)
33                 fprintdecimal(stream,(unsigned long)x);
34         else {
35                 fprintchar(stream,'-');
36                 fprintdecimal(stream,(unsigned long)(-1-x)+1);
37         }
38 }
39
40 }  // namespace cln