template<typename T>
static inline std::string ToHex(T i, size_t width = sizeof(T)) {
std::stringstream stream;
stream << std::hex << std::uppercase << std::setfill('0') << std::setw(width)
<< i;
return stream.str();
}
// Specialized version for uint8_t that don't work well with std::hex.
static inline std::string ToHex(uint8_t i) {
return ToHex(static_cast<int>(i), 2);
}
std::string byte_to_hex(const uint8_t value) {
static const char HEX[] = "0123456789ABCDEF";
uint8_t high = static_cast<uint8_t>(value >> 4);
uint8_t low = static_cast<uint8_t>(value & 0x0F);
return {HEX[high], HEX[low]};
}