UNPKG

dastal

Version:

Data Structures & Algorithms implementations

111 lines (110 loc) 2.42 kB
/** * Bit hacks for 32-bit unsigned numbers. * @module */ /** * Get the number of bits set of a 32-bit unsigned number ([source](https://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel)) * * @param a */ export declare function bitsSet(a: number): number; /** * Invert the bits of a 32-bit unsigned number. * * Example: 11 (1011) -> 4 (0100) * * @param a The number to invert * * @returns The inverted number */ export declare function invert(a: number): number; /** * Check whether a 32-bit unsigned number is a power of 2. * * Example: 8 (1000) -> true * * @param a The number to check */ export declare function isPow2(a: number): boolean; /** * Get the Least Significant Bit of a 32-bit unsigned number * * @param a * * @returns The lowest bit set */ export declare function lsb(a: number): number; /** * Get the Least Significant Power of a 32-bit unsigned number * * @param a * * @returns 2**lsb(a) */ export declare function lsp(a: number): number; /** * Get the Least Significant Power Set of a 32-bit unsigned number. * * Example: 54 (110110) -> 6 (000110) * * @param a */ export declare function lsps(a: number): number; /** * Get the Least Zeroed Bit of a 32-bit unsigned number * * @param a */ export declare function lzb(a: number): number; /** * Get the Least Zeroed Power of a 32-bit unsigned number * * @param a * * @returns 2**lzb(a) */ export declare function lzp(a: number): number; /** * Get the Most Significant Power of the Least Significant Power Set of a 32-bit unsigned number. * * Example: 54 (110110) -> 4 (000100) * * @param a */ /** * Get the Most Significant Bit of a 32-bit unsigned number * * @param a * * @returns ⌊log2(a)⌋ : the highest bit set */ export declare function msb(a: number): number; /** * Get the Most Significant Power of a 32-bit unsigned number * * @param a * * @returns 2**msb(a) */ export declare function msp(a: number): number; /** * Get the Most Significant Power Set of a 32-bit unsigned number. * * Example: 50 (110010) -> 48 (110000) * * @param a */ export declare function msps(a: number): number; /** * Reverse a 32-bit unsigned number. * * Example: 50 (110010) -> 19 (010011) * * @param a */ export declare function reverse(a: number): number; /** * Turn a number into an unsigned 32-bit number * * @param a */ export declare function u32(a: number): number;