| 193 | * @return std::string value in hex, the length will be 2* the raw size of the type |
| 194 | */ |
| 195 | template <typename T> std::string to_hex(T i, bool leading_zeroes = true) |
| 196 | { |
| 197 | char str[26] = { 0 }; |
| 198 | size_t size = sizeof(T) * 2; |
| 199 | std::to_chars(std::begin(str), std::end(str), i, 16); |
| 200 | std::string out{str}; |
| 201 | if (leading_zeroes && out.length() < size) { |
| 202 | out.insert(out.begin(), size - out.length(), '0'); |
| 203 | } |
| 204 | return out; |
| 205 | } |
| 206 | |
| 207 | /** |
| 208 | * @brief Format a numeric type as a string with leading zeroes |
no test coverage detected