| ... | ... | @@ -2,11 +2,23 @@ const std = @import("std"); |
| 2 | 2 | const string = []const u8; |
| 3 | 3 | const extras = @import("./lib.zig"); |
| 4 | 4 | const rawIntBytes = extras.rawIntBytes; |
| 5 | const digits = "0123456789abcdef"; |
| 6 | |
| 7 | const alphabet = blk: { |
| 8 | var data: [512]u8 = @splat('0'); |
| 9 | for (0..16) |m| { |
| 10 | for (0..16) |n| { |
| 11 | data[(m * 16 + n) * 2 + 0] = digits[m]; |
| 12 | data[(m * 16 + n) * 2 + 1] = digits[n]; |
| 13 | } |
| 14 | } |
| 15 | const result = data; |
| 16 | break :blk result; |
| 17 | }; |
| 5 | 18 | |
| 6 | 19 | pub fn to_hex(array: anytype) [array.len * 2]u8 { |
| 7 | 20 | var res: [array.len * 2]u8 = undefined; |
| 8 | | var fbs = std.io.fixedBufferStream(&res); |
| 9 | | std.fmt.format(fbs.writer(), "{x}", .{std.fmt.fmtSliceHexLower(&array)}) catch unreachable; |
| 21 | for (&array, 0..) |x, i| res[i * 2 ..][0..2].* = alphabet[@as(usize, x) * 2 ..][0..2].*; |
| 10 | 22 | return res; |
| 11 | 23 | } |
| 12 | 24 | |