llvm.org GIT mirror llvm / c9debfb
Add llvm::hexdigit to StringExtras (number -> hexadecimal char) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@57536 91177308-0d34-0410-b5e6-96231b3b80d8 Daniel Dunbar 11 years ago
1 changed file(s) with 7 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
2222
2323 namespace llvm {
2424
25 /// hexdigit - Return the (uppercase) hexadecimal character for the
26 /// given number \arg X (which should be less than 16).
27 static inline char hexdigit(unsigned X) {
28 return X < 10 ? '0' + X : 'A' + X - 10;
29 }
30
2531 static inline std::string utohexstr(uint64_t X) {
2632 char Buffer[40];
2733 char *BufPtr = Buffer+39;
3137
3238 while (X) {
3339 unsigned char Mod = static_cast(X) & 15;
34 if (Mod < 10)
35 *--BufPtr = '0' + Mod;
36 else
37 *--BufPtr = 'A' + Mod-10;
40 *--BufPtr = hexdigit(Mod);
3841 X >>= 4;
3942 }
4043 return std::string(BufPtr);