]> www.ginac.de Git - cln.git/blob - src/base/output/cl_output_hex.cc
Initial revision
[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 "cl_io.h"
8
9
10 // Implementation.
11
12 #if defined(CL_IO_STDIO)
13
14 void fprinthexadecimal (cl_ostream stream, unsigned long x)
15 {
16         fprintf(stream,"%lX",x);
17 }
18
19 #endif
20
21 #if defined(CL_IO_IOSTREAM)
22
23 void fprinthexadecimal (cl_ostream stream, unsigned long x)
24 {
25         #define bufsize 16
26         var char buf[bufsize+1];
27         var char* bufptr = &buf[bufsize];
28         *bufptr = '\0';
29         do {
30                 unsigned long q = x / 16;
31                 unsigned long r = x % 16;
32                 *--bufptr = (r<10 ? '0'+r : 'A'-10+r);
33                 x = q;
34         } while (x > 0);
35         fprint(stream,bufptr);
36         #undef bufsize
37 }
38
39 #endif
40
41 void fprinthexadecimal (cl_ostream stream, long x)
42 {
43         if (x >= 0)
44                 fprintdecimal(stream,(unsigned long)x);
45         else {
46                 fprintchar(stream,'-');
47                 fprintdecimal(stream,(unsigned long)(-1-x)+1);
48         }
49 }