Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

extra-bit

Package Overview
Dependencies
Maintainers
1
Versions
147
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

extra-bit

A collection of common bitwise operations.

Source
npmnpm
Version
2.2.41
Version published
Weekly downloads
31
-83.33%
Maintainers
1
Weekly downloads
 
Created
Source

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

PropertyDescription
getGet bits at specified index.
getAsGet bits as per mask.
setSet bits at specified index.
setAsSet bits as per mask.
toggleToggle bits at specified index.
toggleAsToggle bits as per mask.
swapSwap bit sequences at specified indices.
scanFind index of first set bit from LSB.
scanReverseFind index of first set bit from MSB.
countCount bits set.
parityCalculate n-bit parity.
rotateRotate bits by a certain amount.
reverseReverse all bits.
mergeMerge bits as per mask.
interleaveInterleave bits of two int16s.
signExtendSign extend variable bit-width integer.


References




ORG DOI Coverage Status Test Coverage Maintainability

Keywords

extra

FAQs

Package last updated on 14 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts