// Using a single number to store the bits
class BitSet {
constructor() {
this.bits = 0;
}
set(index) {
this.bits |= (1 << index);
}
clear(index) {
this.bits &= ~(1 << index);
}
get(index) {
return (this.bits & (1 << index)) !== 0;
}
print() {
console.log(String(this.bits.toString(2)).padStart(16, '0'));
}
}
const bitset = new BitSet();
bitset.set(5);
bitset.print();
console.log(bitset.get(5)); // true
bitset.clear(5);
console.log(bitset.get(5)); // false
bitset.print();
/*
run:
0000000000100000
true
false
0000000000000000
*/