JSPM

  • Created
  • Published
  • Downloads 22
  • Score
    100M100P100Q76816F
  • License MIT

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

Package Exports

  • extra-bit

Readme

The bit is a basic unit of information in information theory, computing. 🏃 📦 🌔 📒

Methods as separate packages:

This package includes bit twiddling hacks by Sean Eron Anderson and many others.

Stability: Experimental.

const bit = require('extra-bit');
// import * as bit from 'extra-bit';
// import * as bit from 'https://unpkg.com/extra-bit@1.0.26/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 (0xFFFF0000 => 0x0000FFFF)

bit.signExtend(15, 4);
// -1

reference

Method Action
get Gets a bit.
set Sets a bit.
setAs Sets bits as per mask.
swap Swaps bit sequences.
scan Gets index of first set bit from LSB.
scanReverse Gets index of first set bit from MSB.
count Counts bits set.
parity Gets n-bit parity.
reverse Reverses all bits.
merge Merges bits as per mask.
interleave Interleaves bits of two int16s.
signExtend Sign extends variable bit-width integer.

nodef