We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 058a3ce commit d9bc0b9Copy full SHA for d9bc0b9
KaitaiStream.js
@@ -437,11 +437,9 @@ KaitaiStream.prototype.readBitsIntBe = function(n) {
437
438
// raw mask with required number of 1s, starting from lowest bit
439
var mask = n === 32 ? 0xffffffff : (1 << n) - 1;
440
- // shift mask to align with highest bits available in this.bits
+ // shift this.bits to align the highest bits with the mask & derive reading result
441
var shiftBits = this.bitsLeft - n;
442
- mask <<= shiftBits;
443
- // derive reading result
444
- var res = (this.bits & mask) >>> shiftBits;
+ var res = (this.bits >>> shiftBits) & mask;
445
// clear top bits that we've just read => AND with 1s
446
this.bitsLeft -= n;
447
mask = (1 << this.bitsLeft) - 1;
0 commit comments