2 * Set bit on the number
4 export const setBit = (number = 0, mask: number): number => number | mask;
7 * Toggle a bit from the number
9 export const toggleBit = (number = 0, mask: number): number => number ^ mask;
12 * Clear a bit from the number
14 export const clearBit = (number = 0, mask: number): number => number & ~mask;
17 * Check if a bit is set in the number
19 export const hasBit = (number = 0, mask: number): boolean => (number & mask) === mask;
21 export const hasBitBigInt = (number = BigInt(0), mask: bigint): boolean => (number & BigInt(mask)) === BigInt(mask);
24 * Get all bits which are toggled on in the respective bitmap
26 export const getBits = (bitmap: number) => {
27 const size = Math.floor(Math.log2(bitmap)) + 1;
29 const bits: number[] = [];
31 for (let i = 0; i <= size; i++) {
34 if (hasBit(bitmap, bit)) {