SkillAgentSearch skills...

Bitwise

:keycap_ten: JavaScript/TypeScript library to manipulate bits, nibbles, bytes, and buffers.

Install / Use

/learn @FlorianWendelborn/Bitwise
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

<h1 align="center">bitwise</h1> <p align="center"> JavaScript/TypeScript library to manipulate bits, nibbles, bytes, and buffers. </p> <p align="center"> <a href="https://github.com/FlorianWendelborn/bitwise/actions/"><img src="https://img.shields.io/github/actions/workflow/status/FlorianWendelborn/bitwise/pipeline.yml?branch=main&label=actions&logo=github"/></a> <a href="https://codecov.io/gh/FlorianWendelborn/bitwise"><img src="https://img.shields.io/codecov/c/github/FlorianWendelborn/bitwise/master.svg"/></a> <a href="https://npmjs.com/package/bitwise"><img src="https://img.shields.io/npm/dm/bitwise.svg"/></a> <a href="https://npmjs.com/package/bitwise"><img src="https://img.shields.io/npm/dt/bitwise.svg"/></a> <a href="https://bundlephobia.com/result?p=bitwise"><img src="https://img.shields.io/bundlephobia/minzip/bitwise.svg"/></a> </p> <p align="center"> <a href="https://npmjs.com/package/bitwise"><img src="https://img.shields.io/badge/dependencies-none-success.svg"/></a> <a href="https://bundlephobia.com/result?p=bitwise"><img src="https://img.shields.io/badge/tree--shaking-ready-success.svg"/></a> <a href="https://bundlephobia.com/result?p=bitwise"><img src="https://img.shields.io/badge/side--effects-none-success.svg"/></a> <a href="https://openbase.com/js/bitwise?utm_source=embedded&utm_medium=badge&utm_campaign=rate-badge"><img src="https://badges.openbase.com/js/rating/bitwise.svg"/></a> <a href="https://kandi.openweaver.com/typescript/FlorianWendelborn/bitwise"><img src="https://kandi.openweaver.com/badges/xray.svg"/></a> </p>

Example

import bitwise from 'bitwise'

const bits = bitwise.byte.read(42)
// [0, 0, 1, 0, 1, 0, 1, 0]

bitwise.bits.toString(bits, 4)
// '0010 1010'

bitwise.byte.write(bits)
// 42

bitwise.bits.and([0, 0, 1, 1], [0, 1, 0, 1])
// [0, 0, 0, 1]

bitwise.bits.xor([0, 0, 1, 1], [0, 1, 0, 1])
// [0, 1, 1, 0]

// cherry-pick parts of bitwise
import byte from 'bitwise/byte'
byte.read(42)
// [0, 0, 1, 0, 1, 0, 1, 0]

Installation

<pre> <a href="https://bun.sh">bun</a> add bitwise </pre>

or

<pre> <a href="https://yarnpkg.com">yarn</a> add bitwise </pre>

or

<pre> <a href="https://npmjs.com">npm</a> install --save bitwise </pre>

Table of Contents

bits

// cherry-pick
import and from 'bitwise/bits/and'
import bits from 'bitwise/bits'
import toString from 'bitwise/bits/to-string'

bits.and

(bits1: Array<0|1>, bits2: Array<0|1>): Array<0|1>

Applies the bitwise AND operation, expects two arrays of the same size and returns a new one.

bitwise.bits.and([1, 0, 0, 0, 1, 1, 0, 1], [0, 1, 1, 0, 0, 1, 0, 0])
// [0, 0, 0, 0, 0, 1, 0, 0]

bits.circularShiftLeft

(bits: Array<0|1>, amount: number): Array<0|1>

Applies the bitwise ROL operation, expects two arrays of the same size and a shift amount and returns a new one.

bitwise.bits.circularShiftLeft([0, 0, 0, 1, 1, 1, 1, 1], 1)
// [0, 0, 1, 1, 1, 1, 1, 0]

bits.circularShiftRight

(bits: Array<0|1>, amount: number): Array<0|1>

Applies the bitwise ROR operation, expects two arrays of the same size and a shift amount and returns a new one.

bitwise.bits.circularShiftRight([0, 0, 0, 1, 1, 1, 1, 1], 1)
// [1, 0, 0, 0, 1, 1, 1, 1]

bits.nand

(bits1: Array<0|1>, bits2: Array<0|1>): Array<0|1>

Applies the bitwise NAND operation, expects two arrays of the same size and returns a new one.

bitwise.bits.nand([1, 0, 0, 0, 1, 1, 0, 1], [0, 1, 1, 0, 0, 1, 0, 0])
// [1, 1, 1, 0, 1, 0, 0, 1]

bits.nor

(bits1: Array<0|1>, bits2: Array<0|1>): Array<0|1>

Applies the bitwise NOR operation, expects two arrays of the same size and returns a new one.

bitwise.bits.nor([1, 0, 0, 0, 1, 1, 0, 1], [0, 1, 1, 0, 0, 1, 0, 0])
// [1, 1, 1, 0, 1, 0, 0, 1]

bits.not

(bits: Array<0|1>): Array<0|1>

Flips all given bits and returns the flipped bits.

bitwise.bits.not([1, 0, 1, 1, 0, 1])
// [0, 1, 0, 0, 1, 0]

bits.or

(bits1: Array<0|1>, bits2: Array<0|1>): Array<0|1>

Applies the bitwise OR operation, expects two arrays of the same size and returns a new one.

bitwise.bits.or([1, 0, 0, 0, 1, 1, 0, 1], [0, 1, 1, 0, 0, 1, 0, 0])
// [1, 1, 1, 0, 1, 1, 0, 1]

bits.xnor

(bits1: Array<0|1>, bits2: Array<0|1>): Array<0|1>

Applies the bitwise exclusive NOR operation, expects two arrays of the same size and returns a new one.

bitwise.bits.xnor([1, 0, 0, 0, 1, 1, 0, 1], [0, 1, 1, 0, 0, 1, 0, 0])
// [1, 1, 1, 0, 1, 0, 0, 1]

bits.xor

(bits1: Array<0|1>, bits2: Array<0|1>): Array<0|1>

Applies the bitwise exclusive OR operation, expects two arrays of the same size and returns a new one.

bitwise.bits.xor([1, 0, 0, 0, 1, 1, 0, 1], [0, 1, 1, 0, 0, 1, 0, 0])
// [1, 1, 1, 0, 1, 0, 0, 1]

bits.reduceAnd

(bits: Array<0|1>): 0|1

Applies the bitwise AND operation on the given bits. Returns one bit. Throws if less than 2 bits are given.

bitwise.bits.reduceAnd([1, 0, 0, 0, 1, 1, 0, 1])
// 0

bits.reduceNand

(bits: Array<0|1>): 0|1

Applies the NAND operation on the given bits. Returns one bit. Throws if less than 2 bits are given.

bitwise.bits.reduceNand([1, 0, 0, 0, 1, 1, 0, 1])
// 0

bits.reduceNor

(bits: Array<0|1>): 0|1

Applies the NOR operation on the given bits. Returns one bit. Throws if less than 2 bits are given.

bitwise.bits.reduceNor([1, 0, 0, 0, 1, 1, 0, 1])
// 0

bits.reduceOr

(bits: Array<0|1>): 0|1

Applies the OR operation on the given bits. Returns one bit. Throws if less than 2 bits are given.

bitwise.bits.reduceOr([1, 0, 0, 0, 1, 1, 0, 1])
// 1

bits.reduceXnor

(bits: Array<0|1>): 0|1

Applies the XNOR operation on the given bits. Returns one bit. Throws if less than 2 bits are given.

bitwise.bits.reduceXnor([1, 0, 0, 0, 1, 1, 0, 1])
// 1

bits.reduceXor

(bits: Array<0|1>): 0|1

Applies the XOR operation on the given bits. Returns one bit. Throws if less than 2 bits are given.

bitwise.bits.reduceXor([1, 0, 0, 0, 1, 1, 0, 1])
// 0

bits.toBoolean

(bits: Array<0|1>): Array<boolean>

Converts a bit array to a boolean array.

bitwise.bits.toBoolean([0, 1])
// [false, true]

bits.toString

(bits: Array<0|1>, spacing: number = 0, spacer: string = ' '): string

Converts a bit Array to a String. If defined, inserts spacer every spacing characters, but never inserts it as the last substring.

bitwise.bits.toString([1, 0, 1, 0, 1, 0], 2, '_')
// '10_10_10'

buffer

// cherry-pick
import and from 'bitwise/buffer/and'
import buffer from 'bitwise/buffer'
import create from 'bitwise/buffer/create'

buffer.create

(bits: Array<0|1>): Buffer

Creates a new buffer and writes the given bits.

const buffer = bitwise.buffer.create([1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0])
// Buffer(1111 0001 1010 0000)

buffer.modify

(buffer: Buffer, newBits: Array<0|1>, bitOffset: number = 0): void

Modifies the buffer's bits to equal newBits starting at bitOffset.

const buffer = Buffer.from('A43A', 'hex')
bitwise.buffer.modify(buffer, [0, 0, 0, 1, 0, 0, 1], 3)
// Buffer(1010 1001 0011 1010)

buffer.and

(buffer1: Buffer, buffer2: Buffer, isLooping = false): Buffer

Applies a bitwise AND with buffer2 to every value in buffer1. Returns a new buffer. If isLooping is set, buffer1 may be read multiple times in case it's shorter than buffer2.

bitwise.buffer.and(buffer1, buffer2, false)
// Buffer(buffer1 AND buffer2)

buffer.nand

(buffer1: Buffer, buffer2: Buffer, isLooping = false): Buffer

Applies a bitwise NAND with buffer2 to every value in buffer1. Returns a new buffer. If isLooping is set, buffer1 may be read multiple times in case it's shorter than buffer2.

bitwise.buffer.nand(buffer1, buffer2, false)
// Buffer(buffer1 NAND buffer2)

buffer.nor

(buffer1: Buffer, buffer2: Buffer, isLooping = false): Buffer

Applies a bitwise NOR with buffer2 to every value in buffer1. Returns a new buffer. If isLooping is set, buffer1 may be read multiple times in case it's shorter than buffer2.

bitwise.buffer.nor(buffer1, buffer2, false)
// Buffer(buffer1 NOR buffer2)

buffer.not

(buffer: Buffer): Buffer

Flips all bits in the given buffer.

bitwise.buffer.not(buffer, false)
// Buffer(NOT buffer)

buffer.or

(buffer1: Buffer, buffer2: Buffer, isLooping = false): Buffer

Applies a bitwise OR with buffer2 to every value in buffer1. Returns a new buffer. If isLooping is set, buffer1 may be read multiple times in case it's shorter than `b

Related Skills

View on GitHub
GitHub Stars83
CategoryDevelopment
Updated5mo ago
Forks8

Languages

TypeScript

Security Score

97/100

Audited on Oct 8, 2025

No findings