extra-bit.min
v2.0.1
Published
The bit is a basic unit of information in information theory, computing.
Downloads
72
Maintainers
Readme
The bit is a basic unit of information in information theory, computing. This package includes bit twiddling hacks by Sean Eron Anderson and many others. :package: NPM, :smiley_cat: GitHub, :running: RunKit, :vhs: Asciinema, :moon: Minified, :scroll: Files, :newspaper: JSDoc, :blue_book: Wiki.
Stability: Experimental.
This is browserified, minified version of extra-bit. It is exported as global variable bit. CDN: unpkg, jsDelivr.
const bit = require("extra-bit");
// import * as bit from "extra-bit";
// import * as bit from "https://unpkg.com/[email protected]/index.mjs"; (deno)
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 (0x0000FFFF)
bit.signExtend(15, 4);
// -1
Index
| Method | Action | | ------------ | ---------------------------------------- | | get | Gets a bit. | | set | Sets a bit. | | toggle | Toggles a bit. | | swap | Swaps bit sequences. | | scan | Finds index of first set bit from LSB. | | count | Counts bits set. | | parity | Finds n-bit parity. | | rotate | Rotates bits. | | reverse | Reverses all bits. | | merge | Merges bits as per mask. | | interleave | Interleaves bits of two int16s. | | signExtend | Sign extends variable bit-width integer. |