From aebddddaa1dd96e7a86f3ee10cb6c5e89b56d58b Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Tue, 14 Jul 2026 17:45:03 -0700 Subject: [PATCH] add to_HEX --- src/lib.zig | 1 + src/to_hex.zig | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/src/lib.zig b/src/lib.zig index b200eeeaa3e0a87c97123fd55d0f591638d49419..8a26c8d76e4eef1dc0a027ffb542c45b2d95917f 100644 --- a/src/lib.zig +++ b/src/lib.zig @@ -40,6 +40,7 @@ pub const isArrayOf = @import("./isArrayOf.zig").isArrayOf; pub const parse_int = @import("./parse_int.zig").parse_int; pub const parse_bool = @import("./parse_bool.zig").parse_bool; pub const to_hex = @import("./to_hex.zig").to_hex; +pub const to_HEX = @import("./to_hex.zig").to_HEX; pub const FieldUnion = @import("./FieldUnion.zig").FieldUnion; pub const LoggingReader = @import("./LoggingReader.zig").LoggingReader; pub const LoggingWriter = @import("./LoggingWriter.zig").LoggingWriter; diff --git a/src/to_hex.zig b/src/to_hex.zig index 51ed1eedd29ccfdf645b52b8484c4f44b06c1afa..f998d5dd6fb01c5c32a9a433b636f589dce22d79 100644 --- a/src/to_hex.zig +++ b/src/to_hex.zig @@ -22,6 +22,16 @@ pub fn to_hex(array: anytype) [array.len * 2]u8 { return res; } +pub fn to_HEX(array: anytype) [array.len * 2]u8 { + var res: [array.len * 2]u8 = undefined; + for (&array, 0..) |x, i| res[i * 2 ..][0..2].* = alphabet[@as(usize, x) * 2 ..][0..2].*; + for (&res) |*x| x.* = std.ascii.toUpper(x.*); + return res; +} + test { try std.testing.expect(std.mem.eql(u8, &to_hex(rawIntBytes(u64, 0x4e5a7da9f3f1d132)), "4e5a7da9f3f1d132")); } +test { + try std.testing.expect(std.mem.eql(u8, &to_hex(rawIntBytes(u64, 0x4e5a7da9f3f1d132)), "4E5A7dA9F3F1D132")); +} -- 2.54.0