New StringService::toHex() overload for std::uint16_t

This commit is contained in:
Nav
2024-10-06 18:10:30 +01:00
parent d71083c3f9
commit a1dfa56913
2 changed files with 7 additions and 0 deletions

View File

@@ -54,6 +54,12 @@ namespace Services
return stream.str(); return stream.str();
} }
std::string StringService::toHex(std::uint16_t value) {
auto stream = std::stringstream{};
stream << std::hex << std::setfill('0') << std::setw(4) << static_cast<unsigned int>(value);
return stream.str();
}
std::string StringService::toHex(unsigned char value) { std::string StringService::toHex(unsigned char value) {
auto stream = std::stringstream{}; auto stream = std::stringstream{};
stream << std::hex << std::setfill('0') << std::setw(2) << static_cast<unsigned int>(value); stream << std::hex << std::setfill('0') << std::setw(2) << static_cast<unsigned int>(value);

View File

@@ -19,6 +19,7 @@ namespace Services
static std::string toHex(std::uint64_t value); static std::string toHex(std::uint64_t value);
static std::string toHex(std::uint32_t value); static std::string toHex(std::uint32_t value);
static std::string toHex(std::uint16_t value);
static std::string toHex(unsigned char value); static std::string toHex(unsigned char value);
static std::string toHex(const std::vector<unsigned char>& data); static std::string toHex(const std::vector<unsigned char>& data);
static std::string toHex(const std::string& data); static std::string toHex(const std::string& data);