INNER CODE UNIT · TypeScript

remainder

mongodb/js-bson · src/binary.ts:493

    const remainder = bits.length % 8;
    bytes[1] = remainder === 0 ? 0 : 8 - remainder;

    for (let bitOffset = 0; bitOffset < bits.length; bitOffset++) {
      const byteOffset = bitOffset >>> 3; // floor(bitOffset / 8)
      const bit = bits[bitOffset];

      if (bit !== 0 && bit !== 1) {
        throw new BSONError(
          `Invalid bit value at ${bitOffset}: must be 0 or 1, found ${bits[bitOffset]}`
        );
      }

      if (bit === 0) continue;

      const shift = 7 - (bitOffset % 8);
      bytes[byteOffset + 2] |= bit << shift;
    }

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…