1 // fprinthexadecimal().
4 #include "base/cl_sysdep.h"
14 static void fprinthexadecimal_impl (std::ostream& stream, uintptr_t x)
16 #define bufsize (sizeof(uintptr_t)*2)
17 var char buf[bufsize+1];
18 var char* bufptr = &buf[bufsize];
23 *--bufptr = (r<10 ? '0'+r : 'A'-10+r);
26 fprint(stream,bufptr);
30 static void fprinthexadecimal_impl (std::ostream& stream, intptr_t x)
33 fprinthexadecimal(stream,(uintptr_t)x);
35 fprintchar(stream,'-');
36 fprinthexadecimal(stream,(uintptr_t)(-1-x)+1);
40 void fprinthexadecimal (std::ostream& stream, unsigned int x)
42 fprinthexadecimal_impl(stream,(uintptr_t)x);
44 void fprinthexadecimal (std::ostream& stream, int x)
46 fprinthexadecimal_impl(stream,(intptr_t)x);
49 void fprinthexadecimal (std::ostream& stream, unsigned long x)
51 fprinthexadecimal_impl(stream,(uintptr_t)x);
53 void fprinthexadecimal (std::ostream& stream, long x)
55 fprinthexadecimal_impl(stream,(intptr_t)x);
58 void fprinthexadecimal (std::ostream& stream, unsigned long long x)
60 #if long_long_bitsize <= pointer_bitsize
61 fprinthexadecimal_impl(stream,(uintptr_t)x);
63 #define bufsize (sizeof(unsigned long long)*2)
64 var char buf[bufsize+1];
65 var char* bufptr = &buf[bufsize];
68 unsigned long long q = x / 16;
69 unsigned long long r = x % 16;
70 *--bufptr = (r<10 ? '0'+r : 'A'-10+r);
73 fprint(stream,bufptr);
78 void fprinthexadecimal (std::ostream& stream, long long x)
80 #if long_long_bitsize <= pointer_bitsize
81 fprinthexadecimal_impl(stream,(intptr_t)x);
84 fprinthexadecimal(stream,(unsigned long long)x);
86 fprintchar(stream,'-');
87 fprinthexadecimal(stream,(unsigned long long)(-1-x)+1);