Package Exports
- extra-bit
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (extra-bit) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
The bit is a basic unit of information in information theory, computing. This package includes a number of very interesting bit twiddling hacks by Sean Eron Anderson and many others.
Each method is also available as separate package for use by bundling tools, like browserify, rollup, uglify-js.
Stability: Experimental.
const bit = require('extra-bit');
bit.count(7);
// 3 (111 => 3)
bit.parity(8, 2);
// 2 (10,00 => 10)
bit.swap(6, 1, 0);
// 5 (110 => 101)
bit.reverse(0xFFFF0000);
// 65535 (0xFFFF0000 => 0x0000FFFF)
bit.signExtend(15, 4);
// -1reference
| Method | Action |
|---|---|
| get | Gets a bit (right-shift method). |
| set | Sets a bit (left-shift method). |
| setAs | Sets bits as per mask (not method). |
| swap | Swaps bit sequences (xor method). |
| scan | Gets index of first set bit from LSB (mod37 method). |
| scanReverse | Gets index of first set bit from MSB (DeBruijn method). |
| count | Counts bits set (parallel method). |
| parity | Gets n-bit parity. |
| reverse | Reverses all bits (parallel method). |
| merge | Merges bits as per mask (xor method). |
| interleave | Interleaves bits of two int16s (binary magic method). |
| signExtend | Sign extends variable bit-width integer. |
Browserified, minified version of this package is extra-bit.min.