Skip to content

Commit d9bc0b9

Browse files
committed
Simplify readBitsIntBe() as in e1a30e480
1 parent 058a3ce commit d9bc0b9

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

KaitaiStream.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -437,11 +437,9 @@ KaitaiStream.prototype.readBitsIntBe = function(n) {
437437

438438
// raw mask with required number of 1s, starting from lowest bit
439439
var mask = n === 32 ? 0xffffffff : (1 << n) - 1;
440-
// shift mask to align with highest bits available in this.bits
440+
// shift this.bits to align the highest bits with the mask & derive reading result
441441
var shiftBits = this.bitsLeft - n;
442-
mask <<= shiftBits;
443-
// derive reading result
444-
var res = (this.bits & mask) >>> shiftBits;
442+
var res = (this.bits >>> shiftBits) & mask;
445443
// clear top bits that we've just read => AND with 1s
446444
this.bitsLeft -= n;
447445
mask = (1 << this.bitsLeft) - 1;

0 commit comments

Comments
 (0)