add span equality and span for bin2hex

This commit is contained in:
2024-04-10 13:26:54 +02:00
parent 659b410caa
commit bee42d4688
3 changed files with 25 additions and 4 deletions

View File

@@ -44,12 +44,16 @@ std::vector<uint8_t> hex2bin(const std::string_view str) {
return bin;
}
std::string bin2hex(const std::vector<uint8_t>& data) {
std::string bin2hex(const ByteSpan bin) {
std::string str;
for (size_t i = 0; i < data.size(); i++) {
str.push_back(detail::nib_to_hex(data[i] >> 4));
str.push_back(detail::nib_to_hex(data[i] & 0x0f));
for (size_t i = 0; i < bin.size; i++) {
str.push_back(detail::nib_to_hex(bin[i] >> 4));
str.push_back(detail::nib_to_hex(bin[i] & 0x0f));
}
return str;
}
std::string bin2hex(const std::vector<uint8_t>& bin) {
return bin2hex(ByteSpan{bin});
}