Decode unsigned integer values in any base between 10 and 36.
| 60 | |
| 61 | // Decode unsigned integer values in any base between 10 and 36. |
| 62 | int decode(uint64_t value, char* const rc, int radix) |
| 63 | { |
| 64 | int rev = DECODE_BUF_LEN; |
| 65 | if (radix < MIN_RADIX || radix > MAX_RADIX) |
| 66 | radix = MIN_RADIX; |
| 67 | |
| 68 | if (radix == 10) // go faster for this option |
| 69 | { |
| 70 | while (true) |
| 71 | { |
| 72 | rc[rev--] = static_cast<unsigned char>(value % 10) + '0'; |
| 73 | value /= 10; |
| 74 | if (!value) |
| 75 | break; |
| 76 | } |
| 77 | } |
| 78 | else |
| 79 | { |
| 80 | while (true) |
| 81 | { |
| 82 | int temp = static_cast<int>(value % radix); |
| 83 | rc[rev--] = static_cast<unsigned char>(temp < 10 ? temp + '0' : temp - 10 + 'A'); |
| 84 | value /= radix; |
| 85 | if (!value) |
| 86 | break; |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | return adjust_prefix(radix, rev, false, rc); |
| 91 | } |
| 92 | |
| 93 | |
| 94 | // Decode signed integer values in any base between 10 and 36. |
no test coverage detected