A hands-on introduction to bit manipulation and bitwise operators in JavaScript, using the implementation of a BitSet class as a teaching vehicle. Covers bit masks, bitwise AND/OR/NOT/shift operators, and how to build add, remove, and has methods for a BitSet backed by an array of 32-bit integers. Explains how to map an absolute bit index to a word index and bit index using right shift and AND operations. Part 1 of a 2-part series; part 2 covers fast iteration using two's complement and Hamming weights.
Sort: