Gathering detailed insights and metrics for bitwise
Gathering detailed insights and metrics for bitwise
Gathering detailed insights and metrics for bitwise
Gathering detailed insights and metrics for bitwise
buffer-xor
A simple module for bitwise-xor on buffers
bitwise-xor
Bitwise XOR between two Buffers or Strings, returns a Buffer
bitwise-buffer
A simple module for bitwise operations on buffers.
@putout/plugin-convert-bitwise-to-logical
🐊Putout plugin adds ability to convert bitwice to logical operator
🔟 JavaScript/TypeScript library to manipulate bits, nibbles, bytes, and buffers.
npm install bitwise
Typescript
Module System
Node Version
NPM Version
TypeScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
81 Stars
164 Commits
8 Forks
2 Watchers
3 Branches
4 Contributors
Updated on Mar 26, 2025
Latest Version
2.2.1
Package Id
bitwise@2.2.1
Unpacked Size
128.26 kB
Size
18.50 kB
File Count
187
NPM Version
10.2.5
Node Version
20.10.0
Published on
Dec 13, 2023
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
3
JavaScript/TypeScript library to manipulate bits, nibbles, bytes, and buffers.
1import bitwise from 'bitwise' 2 3const bits = bitwise.byte.read(42) 4// [0, 0, 1, 0, 1, 0, 1, 0] 5 6bitwise.bits.toString(bits, 4) 7// '0010 1010' 8 9bitwise.byte.write(bits) 10// 42 11 12bitwise.bits.and([0, 0, 1, 1], [0, 1, 0, 1]) 13// [0, 0, 0, 1] 14 15bitwise.bits.xor([0, 0, 1, 1], [0, 1, 0, 1]) 16// [0, 1, 1, 0] 17 18// cherry-pick parts of bitwise 19import byte from 'bitwise/byte' 20byte.read(42) 21// [0, 0, 1, 0, 1, 0, 1, 0]
bun add bitwise
or
yarn add bitwise
or
npm install --save bitwise
1// cherry-pick 2import and from 'bitwise/bits/and' 3import bits from 'bitwise/bits' 4import toString from 'bitwise/bits/to-string'
1(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.
1bitwise.bits.and([1, 0, 0, 0, 1, 1, 0, 1], [0, 1, 1, 0, 0, 1, 0, 0]) 2// [0, 0, 0, 0, 0, 1, 0, 0]
1(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.
1bitwise.bits.circularShiftLeft([0, 0, 0, 1, 1, 1, 1, 1], 1) 2// [0, 0, 1, 1, 1, 1, 1, 0]
1(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.
1bitwise.bits.circularShiftRight([0, 0, 0, 1, 1, 1, 1, 1], 1) 2// [1, 0, 0, 0, 1, 1, 1, 1]
1(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.
1bitwise.bits.nand([1, 0, 0, 0, 1, 1, 0, 1], [0, 1, 1, 0, 0, 1, 0, 0]) 2// [1, 1, 1, 0, 1, 0, 0, 1]
1(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.
1bitwise.bits.nor([1, 0, 0, 0, 1, 1, 0, 1], [0, 1, 1, 0, 0, 1, 0, 0]) 2// [1, 1, 1, 0, 1, 0, 0, 1]
1(bits: Array<0|1>): Array<0|1>
Flips all given bits and returns the flipped bits.
1bitwise.bits.not([1, 0, 1, 1, 0, 1]) 2// [0, 1, 0, 0, 1, 0]
1(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.
1bitwise.bits.or([1, 0, 0, 0, 1, 1, 0, 1], [0, 1, 1, 0, 0, 1, 0, 0]) 2// [1, 1, 1, 0, 1, 1, 0, 1]
1(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.
1bitwise.bits.xnor([1, 0, 0, 0, 1, 1, 0, 1], [0, 1, 1, 0, 0, 1, 0, 0]) 2// [1, 1, 1, 0, 1, 0, 0, 1]
1(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.
1bitwise.bits.xor([1, 0, 0, 0, 1, 1, 0, 1], [0, 1, 1, 0, 0, 1, 0, 0]) 2// [1, 1, 1, 0, 1, 0, 0, 1]
1(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.
1bitwise.bits.reduceAnd([1, 0, 0, 0, 1, 1, 0, 1]) 2// 0
1(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.
1bitwise.bits.reduceNand([1, 0, 0, 0, 1, 1, 0, 1]) 2// 0
1(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.
1bitwise.bits.reduceNor([1, 0, 0, 0, 1, 1, 0, 1]) 2// 0
1(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.
1bitwise.bits.reduceOr([1, 0, 0, 0, 1, 1, 0, 1]) 2// 1
1(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.
1bitwise.bits.reduceXnor([1, 0, 0, 0, 1, 1, 0, 1]) 2// 1
1(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.
1bitwise.bits.reduceXor([1, 0, 0, 0, 1, 1, 0, 1]) 2// 0
1(bits: Array<0|1>): Array<boolean>
Converts a bit array to a boolean array.
1bitwise.bits.toBoolean([0, 1]) 2// [false, true]
1(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.
1bitwise.bits.toString([1, 0, 1, 0, 1, 0], 2, '_') 2// '10_10_10'
1// cherry-pick 2import and from 'bitwise/buffer/and' 3import buffer from 'bitwise/buffer' 4import create from 'bitwise/buffer/create'
1(bits: Array<0|1>): Buffer
Creates a new buffer and writes the given bits.
1const buffer = bitwise.buffer.create([1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0]) 2// Buffer(1111 0001 1010 0000)
1(buffer: Buffer, newBits: Array<0|1>, bitOffset: number = 0): void
Modifies the buffer's bits to equal newBits
starting at bitOffset
.
1const buffer = Buffer.from('A43A', 'hex') 2bitwise.buffer.modify(buffer, [0, 0, 0, 1, 0, 0, 1], 3) 3// Buffer(1010 1001 0011 1010)
1(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
.
1bitwise.buffer.and(buffer1, buffer2, false) 2// Buffer(buffer1 AND buffer2)
1(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
.
1bitwise.buffer.nand(buffer1, buffer2, false) 2// Buffer(buffer1 NAND buffer2)
1(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
.
1bitwise.buffer.nor(buffer1, buffer2, false) 2// Buffer(buffer1 NOR buffer2)
1(buffer: Buffer): Buffer
Flips all bits in the given buffer.
1bitwise.buffer.not(buffer, false) 2// Buffer(NOT buffer)
1(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 buffer2
.
1bitwise.buffer.or(buffer1, buffer2, false) 2// Buffer(buffer1 OR buffer2)
1(buffer1: Buffer, buffer2: Buffer, isLooping = false): Buffer
Applies a bitwise XNOR
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
.
1bitwise.buffer.xnor(buffer1, buffer2, false) 2// Buffer(buffer1 XNOR buffer2)
1(buffer1: Buffer, buffer2: Buffer, isLooping = false): Buffer
Applies a bitwise XOR
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
.
1bitwise.buffer.xor(buffer1, buffer2, false) 2// Buffer(buffer1 XOR buffer2)
1(buffer: Buffer, bitOffset: number = 0, bitLength?: number): Array<0|1>
Returns an Array containing bitLength
bits starting at bitOffset
. If no bitLength
is given, it's assumed to be the rest of the buffer.
1const buffer = Buffer.from('ED743E17', 'hex') 2bitwise.buffer.read(buffer, 12) 3// [0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1]
1(buffer: Buffer, bitOffset: number = 0, bitLength: number = 8): number
Converts a section of a buffer to a signed integer.
1// buffer 11110110 2bitwise.buffer.readInt(buffer, 3, 5) 3// -10
1(buffer: Buffer, bitOffset: number = 0, bitLength: number = 8): number
Converts a section of a buffer to an unsigned integer.
1// buffer 11110110 2bitwise.buffer.readUInt(buffer, 3, 5) 3// 22
1// cherry-pick 2import byte from 'bitwise/byte' 3import read from 'bitwise/byte/read'
1(byte: UInt8): Array<0|1>
Returns an Array of length 8 containing the read bits.
1bitwise.byte.read(42) 2// [0, 0, 1, 0, 1, 0, 1, 0] 3bitwise.byte.read(256) 4// RangeError('invalid size')
1(bits: Array<0|1>): UInt8
Returns a Byte (0-255) which represents the given bits.
1bitwise.byte.write([0, 0, 1, 0, 1, 0, 1, 0]) 2// 42 3bitwise.byte.write([0, 0, 1, 0, 1, 0, 1, 0, 0]) 4// RangeError('invalid array length')
1// cherry-pick 2import integer from 'bitwise/integer'
1(number: number, position: number): 0|1
Gets the value of a specific bit.
1bitwise.integer.getBit(128, 7) 2// 1
1(number: number, position: number, value: 0|1): Array<0|1>
Sets the value of a specific bit.
1bitwise.integer.setBit(128, 7, 0) 2// 0
1(number: number, position: number): Array<0|1>
Toggles the value of a specific bit.
1bitwise.integer.toggleBit(128, 7) 2// 0
1// cherry-pick 2import nibble from 'bitwise/nibble' 3import read from 'bitwise/nibble/read'
1(nibble: UInt4): Array<0|1>
Returns an Array of length 4 containing the read bits.
1bitwise.nibble.read(15) 2// [1, 1, 1, 1] 3bitwise.nibble.read(42) 4// RangeError('invalid size')
1(nibble: [<0|1>, <0|1>, <0|1>, <0|1>]): UInt4
Returns a Nibble (0-15
) which represents the given bits.
1bitwise.nibble.write([0, 0, 1, 0]) 2// 2 3bitwise.nibble.write([0, 0, 1, 0, 1]) 4// RangeError('invalid array length')
1// cherry-pick 2import string from 'bitwise/string' 3import toBits from 'bitwise/string/to-bits'
1(string: string): Array<0|1>
Converts a string into an array of bits. Ignores all characters except 1
and 0
.
1bitwise.string.toBits('10 10 12$%_.0') 2// [1, 0, 1, 0, 1, 0]
bitwise
uses bun
instead of node
1# install dependencies 2bun install 3 4# run tests 5bun test 6 7# build 8bun run build
typescript
from dependencies
in favor of devDependencies
bun
bits.circularShiftLeft
(#44 / #49) via @0xflotusbits.circularShiftRight
(#44 / #49) via @0xflotusbitwise.buffer.readCInt()
require()
supportbits.toBoolean
bits.reduceAnd
bits.reduceNand
bits.reduceNor
bits.reduceOr
bits.reduceXnor
bits.reduceXor
buffer.operations
bits.operations
integer.getBit
integer.setBit
integer.toggleBit
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
Found 1/26 approved changesets -- score normalized to 0
Reason
0 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More