Skip to content

Commit 3cd26eb

Browse files
committed
Simplify read_bits_int_be as in kaitai-io/kaitai_struct_java_runtime@e1a30e4
1 parent 7a9fe3f commit 3cd26eb

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

kaitaistruct.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,9 @@ def read_bits_int_be(self, n):
237237

238238
# raw mask with required number of 1s, starting from lowest bit
239239
mask = (1 << n) - 1
240-
# shift mask to align with highest bits available in self.bits
240+
# shift self.bits to align the highest bits with the mask & derive reading result
241241
shift_bits = self.bits_left - n
242-
mask <<= shift_bits
243-
# derive reading result
244-
res = (self.bits & mask) >> shift_bits
242+
res = (self.bits >> shift_bits) & mask
245243
# clear top bits that we've just read => AND with 1s
246244
self.bits_left -= n
247245
mask = (1 << self.bits_left) - 1

0 commit comments

Comments
 (0)