preserve bin2hex size

This commit is contained in:
Green Sky 2024-12-01 12:49:48 +01:00
parent a38c3a3305
commit 717748e8fc
No known key found for this signature in database

View File

@ -46,6 +46,7 @@ std::vector<uint8_t> hex2bin(const std::string_view str) {
std::string bin2hex(const ByteSpan bin) { std::string bin2hex(const ByteSpan bin) {
std::string str; std::string str;
str.reserve(bin.size*2);
for (size_t i = 0; i < bin.size; i++) { 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] >> 4));
str.push_back(detail::nib_to_hex(bin[i] & 0x0f)); str.push_back(detail::nib_to_hex(bin[i] & 0x0f));