authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-07-14 17:45:03 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-07-14 17:45:03 -07:00
logaebddddaa1dd96e7a86f3ee10cb6c5e89b56d58b
tree9c9e24d88a606260ad11a4f2d384d8473755fa53
parent02301520811d7796de6e4f87961a44a6f458f702
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

add to_HEX


2 files changed, 11 insertions(+), 0 deletions(-)

src/lib.zig+1
......@@ -40,6 +40,7 @@ pub const isArrayOf = @import("./isArrayOf.zig").isArrayOf;
4040pub const parse_int = @import("./parse_int.zig").parse_int;
4141pub const parse_bool = @import("./parse_bool.zig").parse_bool;
4242pub const to_hex = @import("./to_hex.zig").to_hex;
43pub const to_HEX = @import("./to_hex.zig").to_HEX;
4344pub const FieldUnion = @import("./FieldUnion.zig").FieldUnion;
4445pub const LoggingReader = @import("./LoggingReader.zig").LoggingReader;
4546pub const LoggingWriter = @import("./LoggingWriter.zig").LoggingWriter;
src/to_hex.zig+10
......@@ -22,6 +22,16 @@ pub fn to_hex(array: anytype) [array.len * 2]u8 {
2222 return res;
2323}
2424
25pub fn to_HEX(array: anytype) [array.len * 2]u8 {
26 var res: [array.len * 2]u8 = undefined;
27 for (&array, 0..) |x, i| res[i * 2 ..][0..2].* = alphabet[@as(usize, x) * 2 ..][0..2].*;
28 for (&res) |*x| x.* = std.ascii.toUpper(x.*);
29 return res;
30}
31
2532test {
2633 try std.testing.expect(std.mem.eql(u8, &to_hex(rawIntBytes(u64, 0x4e5a7da9f3f1d132)), "4e5a7da9f3f1d132"));
2734}
35test {
36 try std.testing.expect(std.mem.eql(u8, &to_hex(rawIntBytes(u64, 0x4e5a7da9f3f1d132)), "4E5A7dA9F3F1D132"));
37}