15using ByteAsHex = std::array<char, 2>;
17constexpr std::array<ByteAsHex, 256> CreateByteToHexMap()
19 constexpr char hexmap[16] = {
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'a',
'b',
'c',
'd',
'e',
'f'};
21 std::array<ByteAsHex, 256> byte_to_hex{};
22 for (
size_t i = 0; i < byte_to_hex.size(); ++i) {
23 byte_to_hex[i][0] = hexmap[i >> 4];
24 byte_to_hex[i][1] = hexmap[i & 15];
31std::string
HexStr(
const std::span<const uint8_t>
s)
33 std::string rv(
s.size() * 2,
'\0');
34 static constexpr auto byte_to_hex = CreateByteToHexMap();
35 static_assert(
sizeof(byte_to_hex) == 512);
39 std::memcpy(it, byte_to_hex[v].
data(), 2);
43 assert(it == rv.data() + rv.size());
48{ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
49 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
50 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
51 0,1,2,3,4,5,6,7,8,9,-1,-1,-1,-1,-1,-1,
52 -1,0xa,0xb,0xc,0xd,0xe,0xf,-1,-1,-1,-1,-1,-1,-1,-1,-1,
53 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
54 -1,0xa,0xb,0xc,0xd,0xe,0xf,-1,-1,-1,-1,-1,-1,-1,-1,-1,
55 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
56 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
57 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
58 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
59 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
60 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
61 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
62 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
63 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, };
const signed char p_util_hexdigit[256]
signed char HexDigit(char c)
std::string HexStr(const std::span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.