Skip to content

extra-bit 2.2.39

Install from the command line:
Learn more about npm packages
$ npm install @nodef/extra-bit@2.2.39
Install via package.json:
"@nodef/extra-bit": "2.2.39"

About this version

A collection of common bitwise operations.
πŸ“¦ Node.js, 🌐 Web, πŸ“œ Files, πŸ“° Docs, πŸ“˜ Wiki.

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. JavaScript converts a Number (a 64-bit floating point number) to a 32-bit integer when bitwise operators (such as |) are applied. All bitwise operations are performed on 32-bit integers.

This package is available in Node.js and Web formats. The web format is exposed as extra_bit standalone variable and can be loaded from jsDelivr CDN.

Stability: Experimental.


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

Property Description
get Get bits at specified index.
getAs Get bits as per mask.
set Set bits at specified index.
setAs Set bits as per mask.
toggle Toggle bits at specified index.
toggleAs Toggle bits as per mask.
swap Swap bit sequences at specified indices.
scan Find index of first set bit from LSB.
scanReverse Find index of first set bit from MSB.
count Count bits set.
parity Calculate n-bit parity.
rotate Rotate bits by a certain amount.
reverse Reverse all bits.
merge Merge bits as per mask.
interleave Interleave bits of two int16s.
signExtend Sign extend variable bit-width integer.


References




ORG DOI Coverage Status Test Coverage Maintainability

Details


Assets

  • extra-bit-2.2.39.tgz

Download activity

  • Total downloads 0
  • Last 30 days 0
  • Last week 0
  • Today 0