diff options
Diffstat (limited to 'src/base32.zig')
-rw-r--r-- | src/base32.zig | 20 |
1 files changed, 5 insertions, 15 deletions
diff --git a/src/base32.zig b/src/base32.zig index d612e7a..749c313 100644 --- a/src/base32.zig +++ b/src/base32.zig | |||
@@ -64,18 +64,8 @@ pub const Encoder = struct { | |||
64 | /// | 6 | 0b11000 | | 64 | /// | 6 | 0b11000 | |
65 | /// | 7 | 0b10000 | | 65 | /// | 7 | 0b10000 | |
66 | fn frontBits(self: *const Self) ?u5 { | 66 | fn frontBits(self: *const Self) ?u5 { |
67 | // bit_off bitmask shl shr frontBits | ||
68 | // 0 0b11111000 3 0b11111 | ||
69 | // 1 0b01111100 2 0b11111 | ||
70 | // 2 0b00111110 1 0b11111 | ||
71 | // 3 0b00011111 0 0 0b11111 | ||
72 | // 4 0b00001111 1 0b11110 | ||
73 | // 5 0b00000111 2 0b11100 | ||
74 | // 6 0b00000011 3 0b11000 | ||
75 | // 7 0b00000001 4 0b10000 | ||
76 | const index = self.index orelse return null; | 67 | const index = self.index orelse return null; |
77 | const bitmask = @as(u8, 0b11111000) >> self.bit_off; | 68 | const bits = self.buffer[index]; |
78 | const bits = self.buffer[index] & bitmask; | ||
79 | if (self.bit_off >= 4) return @truncate(u5, bits << (self.bit_off - 3)); | 69 | if (self.bit_off >= 4) return @truncate(u5, bits << (self.bit_off - 3)); |
80 | return @truncate(u5, bits >> (3 - self.bit_off)); | 70 | return @truncate(u5, bits >> (3 - self.bit_off)); |
81 | } | 71 | } |
@@ -87,10 +77,10 @@ pub const Encoder = struct { | |||
87 | /// | `bits` | `backBits` | | 77 | /// | `bits` | `backBits` | |
88 | /// |--------|------------| | 78 | /// |--------|------------| |
89 | /// | 0 | 0b00000 | | 79 | /// | 0 | 0b00000 | |
90 | /// | 1 | 0b10000 | | 80 | /// | 1 | 0b00001 | |
91 | /// | 2 | 0b11000 | | 81 | /// | 2 | 0b00011 | |
92 | /// | 3 | 0b11100 | | 82 | /// | 3 | 0b00111 | |
93 | /// | 4 | 0b11100 | | 83 | /// | 4 | 0b01110 | |
94 | /// | 5 | 0b11101 | | 84 | /// | 5 | 0b11101 | |
95 | fn backBits(self: *const Self, bits: u3) u5 { | 85 | fn backBits(self: *const Self, bits: u3) u5 { |
96 | std.debug.assert(bits <= 5); | 86 | std.debug.assert(bits <= 5); |