UNPKG

extra-bit

Version:

The bit is a basic unit of information in information theory, computing.

120 lines (118 loc) 3.56 kB
/** * Get bits at specified index. * [📘](https://github.com/nodef/extra-bit/wiki/get) * @param x an int32 * @param i bit index * @param w bit width [1] */ declare function get(x: number, i: number, w?: number): number; /** * Get bits as per mask. * [📘](https://github.com/nodef/extra-bit/wiki/getAs) * @param x an int32 * @param m bit mask */ declare function getAs(x: number, m: number): number; /** * Set bits at specified index. * [📘](https://github.com/nodef/extra-bit/wiki/set) * @param x an int32 * @param i bit index * @param v bit value [1] * @param w bit width [1] */ declare function set(x: number, i: number, v?: number, w?: number): number; /** * Set bits as per mask. * [📘](https://github.com/nodef/extra-bit/wiki/setAs) * @param x an int32 * @param m bit mask * @param f bit value [1] */ declare function setAs(x: number, m: number, f?: number): number; /** * Toggle bits at specified index. * [📘](https://github.com/nodef/extra-bit/wiki/toggle) * @param x an int32 * @param i bit index * @param w bit width [1] */ declare function toggle(x: number, i: number, w?: number): number; /** * Toggle bits as per mask. * [📘](https://github.com/nodef/extra-bit/wiki/toggleAs) * @param x an int32 * @param m bit mask */ declare function toggleAs(x: number, m: number): number; /** * Swap bit sequences at specified indices. * [📘](https://github.com/nodef/extra-bit/wiki/swap) * @param x an int32 * @param i first bit index * @param j second bit index * @param w bit width [1] */ declare function swap(x: number, i: number, j: number, w?: number): number; /** * Find index of first set bit from LSB. * [📘](https://github.com/nodef/extra-bit/wiki/scan) * @param x an int32 */ declare function scan(x: number): number; /** * Find index of first set bit from MSB. * [📘](https://github.com/nodef/extra-bit/wiki/scanReverse) * @param x an int32 */ declare function scanReverse(x: number): number; /** * Count bits set. * [📘](https://github.com/nodef/extra-bit/wiki/count) * @param x an int32 */ declare function count(x: number): number; /** * Calculate n-bit parity. * [📘](https://github.com/nodef/extra-bit/wiki/parity) * @param x an int32 * @param n number of bits [1] */ declare function parity(x: number, n?: number): number; /** * Rotate bits by a certain amount. * [📘](https://github.com/nodef/extra-bit/wiki/rotate) * @param x an int32 * @param n rotate amount (+ve: left, -ve: right) */ declare function rotate(x: number, n?: number): number; /** * Reverse all bits. * [📘](https://github.com/nodef/extra-bit/wiki/reverse) * @param x an int32 */ declare function reverse(x: number): number; /** * Merge bits as per mask. * [📘](https://github.com/nodef/extra-bit/wiki/merge) * @param x first int32 * @param y second int32 * @param m bit mask (0 ⇒ from x) */ declare function merge(x: number, y: number, m: number): number; /** * Interleave bits of two int16s. * [📘](https://github.com/nodef/extra-bit/wiki/interleave) * @param x first int16 * @param y second int16 * @returns int32 */ declare function interleave(x: number, y: number): number; /** * Sign extend variable bit-width integer. * [📘](https://github.com/nodef/extra-bit/wiki/signExtend) * @param x variable bit-width integer * @param w bit width (32) */ declare function signExtend(x: number, w?: number): number; export { count, get, getAs, interleave, merge, parity, reverse, rotate, scan, scanReverse, set, setAs, signExtend, swap, toggle, toggleAs };