From 2b39ce9bc8ceef8e6ea22ae635f963ce1943848f Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Mon, 27 Apr 2020 23:25:47 +0200 Subject: [PATCH] Simplify ReadBitsIntBe as in kaitai-io/kaitai_struct_java_runtime@e1a30e4 --- KaitaiStream.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/KaitaiStream.cs b/KaitaiStream.cs index 5a1bf06..936dd81 100644 --- a/KaitaiStream.cs +++ b/KaitaiStream.cs @@ -307,11 +307,9 @@ namespace Kaitai // raw mask with required number of 1s, starting from lowest bit ulong mask = GetMaskOnes(n); - // shift mask to align with highest bits available in "bits" + // shift "bits" to align the highest bits with the mask & derive reading result int shiftBits = BitsLeft - n; - mask = mask << shiftBits; - // derive reading result - ulong res = (Bits & mask) >> shiftBits; + ulong res = (Bits >> shiftBits) & mask; // clear top bits that we've just read => AND with 1s BitsLeft -= n; mask = GetMaskOnes(BitsLeft);