| ... | @@ -2722,7 +2722,7 @@ test "recursive format function" { | ... | @@ -2722,7 +2722,7 @@ test "recursive format function" { |
| 2722 | pub const hex_charset = "0123456789abcdef"; | 2722 | pub const hex_charset = "0123456789abcdef"; |
| 2723 | | 2723 | |
| 2724 | /// Converts an unsigned integer of any multiple of u8 to an array of lowercase | 2724 | /// Converts an unsigned integer of any multiple of u8 to an array of lowercase |
| 2725 | /// hex bytes. | 2725 | /// hex bytes, little endian. |
| 2726 | pub fn hex(x: anytype) [@sizeOf(@TypeOf(x)) * 2]u8 { | 2726 | pub fn hex(x: anytype) [@sizeOf(@TypeOf(x)) * 2]u8 { |
| 2727 | comptime assert(@typeInfo(@TypeOf(x)).Int.signedness == .unsigned); | 2727 | comptime assert(@typeInfo(@TypeOf(x)).Int.signedness == .unsigned); |
| 2728 | var result: [@sizeOf(@TypeOf(x)) * 2]u8 = undefined; | 2728 | var result: [@sizeOf(@TypeOf(x)) * 2]u8 = undefined; |
| ... | @@ -2739,17 +2739,11 @@ test hex { | ... | @@ -2739,17 +2739,11 @@ test hex { |
| 2739 | { | 2739 | { |
| 2740 | const x = hex(@as(u32, 0xdeadbeef)); | 2740 | const x = hex(@as(u32, 0xdeadbeef)); |
| 2741 | try std.testing.expect(x.len == 8); | 2741 | try std.testing.expect(x.len == 8); |
| 2742 | switch (builtin.cpu.arch.endian()) { | 2742 | try std.testing.expectEqualStrings("efbeadde", &x); |
| 2743 | .little => try std.testing.expectEqualStrings("efbeadde", &x), | | |
| 2744 | .big => try std.testing.expectEqualStrings("deadbeef", &x), | | |
| 2745 | } | | |
| 2746 | } | 2743 | } |
| 2747 | { | 2744 | { |
| 2748 | const s = "[" ++ hex(@as(u64, 0x12345678_abcdef00)) ++ "]"; | 2745 | const s = "[" ++ hex(@as(u64, 0x12345678_abcdef00)) ++ "]"; |
| 2749 | try std.testing.expect(s.len == 18); | 2746 | try std.testing.expect(s.len == 18); |
| 2750 | switch (builtin.cpu.arch.endian()) { | 2747 | try std.testing.expectEqualStrings("[00efcdab78563412]", s); |
| 2751 | .little => try std.testing.expectEqualStrings("[00efcdab78563412]", s), | | |
| 2752 | .big => try std.testing.expectEqualStrings("[12345678abcdef00]", s), | | |
| 2753 | } | | |
| 2754 | } | 2748 | } |
| 2755 | } | 2749 | } |