Encodes a sequence of bytes as hexadecimal digits. Returns an array containing the encoded bytes.
pub fn bytesToHex(input: anytype, case: Case) [input.len * 2]u8
pub fn bytesToHex(input: anytype, case: Case) [input.len * 2]u8 {
if (input.len == 0) return [_]u8{};
comptime assert(@TypeOf(input[0]) == u8); // elements to encode must be unsigned bytes
const charset = "0123456789" ++ if (case == .upper) "ABCDEF" else "abcdef";
var result: [input.len * 2]u8 = undefined;
for (input, 0..) |b, i| {
result[i * 2 + 0] = charset[b >> 4];
result[i * 2 + 1] = charset[b & 15];
}
return result;
}