Gathering detailed insights and metrics for bitwise-operation
Gathering detailed insights and metrics for bitwise-operation
Gathering detailed insights and metrics for bitwise-operation
Gathering detailed insights and metrics for bitwise-operation
bitwise-operations
bitwise operations
symbolic-operation
A collection of utility functions implemented using bitwise operations for optimized performance.
@thi.ng/binary
100+ assorted binary / bitwise operations, conversions, utilities, lookup tables
extra-bit
The bit is a basic unit of information in information theory, computing.
bitwise-operation is a JavaScript library that provides useful bitwise operation helpers without converting integer to an array.
npm install bitwise-operation
Typescript
Module System
Node Version
NPM Version
TypeScript (51.35%)
JavaScript (45.17%)
HTML (3.48%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
4 Stars
17 Commits
1 Watchers
1 Branches
2 Contributors
Updated on Aug 21, 2022
Latest Version
2.0.3
Package Id
bitwise-operation@2.0.3
Unpacked Size
22.77 kB
Size
5.11 kB
File Count
7
NPM Version
8.19.2
Node Version
16.18.0
Published on
Jul 06, 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
bitwise-operation
is a JavaScript library that provides useful bitwise operation helpers without converting integer to an array.
Node.js npm install --save bitwise-operation
Require.js require(["bitwise"], ...
Require in Node var Bitwise = require('bitwise-operation');
Import in Node import { Bitwise } from "bitwise-operation";
Broser <script src="/node_modules/bitwise-operation/bitwise.js"></script>
new Bitwise(value)
Create a bitwise object to chain operations.
Example:
1import { Bitwise } from "bitwise-operation"; 2 3new Bitwise(0b1011); 4 5var value = new Bitwise([1, 1, 0, 1]); 6value.valueOf(); // 0b1011 7 8new Bitwise("1011");
Bitwise.chain(value)
Create a bitwise object to chain operations.
Example:
1import { Bitwise } from "bitwise-operation"; 2 3Bitwise.chain(0b0100).and(0b1100).or(0b0010).valueOf(); 4// => 0b0110
Bitwise.not(value)
Bitwise.chain(value).not()
Performs a logical NOT of this target bit set.
Truth table:
a | NOT a |
---|---|
0 | 1 |
1 | 0 |
Example:
1import { Bitwise } from "bitwise-operation"; 2 3Bitwise.not(0b1010); 4Bitwise.chain(0b1010).not().valueOf(); 5 6// => 0b0101
Bitwise.and(...values)
Bitwise.chain(value).and(value)
Performs a logical AND of this target bit set with the argument bit set.
Truth table:
a | b | a AND b |
---|---|---|
0 | 0 | 0 |
0 | 1 | 0 |
1 | 0 | 0 |
1 | 1 | 1 |
Example:
1import { Bitwise } from "bitwise-operation"; 2 3Bitwise.and(0b0111, Bitwise(0b0101), 0b1100); 4 5Bitwise.chain(0b0111).and(Bitwise(0b0101)).and(0b1100).valueOf(); 6 7// => 0b0100
Bitwise.nand(...values)
Bitwise.chain(value).nand(value)
Clears all of the bits in this BitSet whose corresponding bit is set in the specified BitSet.
Truth table:
a | b | a NAND b |
---|---|---|
0 | 0 | 1 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 0 |
Example:
1import { Bitwise } from "bitwise-operation"; 2 3Bitwise.nand(0b0010, 0b0110); 4 5Bitwise.chain(0b0010).nand(0b0110).valueOf(); 6 7// => 0b1101
Alias: andNot()
Bitwise.or(...values)
Bitwise.chain(value).or(value)
Performs a logical OR of this bit set with the bit set argument.
Truth table:
a | b | a OR b |
---|---|---|
0 | 0 | 0 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 1 |
Example:
1import { Bitwise } from "bitwise-operation"; 2 3Bitwise.or(0b0010, 0b0110); 4 5Bitwise.chain(0b0010).or(0b0110).valueOf(); 6 7// => 0b0110
Bitwise.nor(...values)
Bitwise.chain(value).nor(value)
Performs a logical NOR of this bit set with the bit set argument.
Truth table:
a | b | a NOR b |
---|---|---|
0 | 0 | 1 |
0 | 1 | 0 |
1 | 0 | 0 |
1 | 1 | 0 |
Example:
1import { Bitwise } from "bitwise-operation"; 2 3Bitwise.nor(0b0010, 0b0110); 4 5Bitwise.chain(0b0010).nor(0b0110).valueOf(); 6 7// => 0b1001
Bitwise.xor(...values)
Bitwise.chain(value).xor(value)
Performs a logical XOR of this bit set with the bit set argument.
Truth table:
a | b | a XOR b |
---|---|---|
0 | 0 | 0 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 0 |
Example:
1import { Bitwise } from "bitwise-operation"; 2 3Bitwise.xor(0b0010, 0b0110); 4 5Bitwise.chain(0b0010).xor(0b0110).valueOf(); 6 7// => 0b0100
Bitwise.xnor(...values)
Bitwise.chain(value).xnor(value)
Performs a logical XNOR of this bit set with the bit set argument.
Truth table:
a | b | a XNOR b |
---|---|---|
0 | 0 | 1 |
0 | 1 | 0 |
1 | 0 | 0 |
1 | 1 | 1 |
Example:
1import { Bitwise } from "bitwise-operation"; 2 3Bitwise.xor(0b0010, 0b0110); 4 5Bitwise.chain(0b0010).xor(0b0110).valueOf(); 6 7// => 0b1011
Alias: nxor()
Bitwise.mask([fromIndex= 0,] toIndex)
Bitwise.chain(value).mask([fromIndex= 0,] toIndex)
Sets the bits not in the specified fromIndex (inclusive) to the specified toIndex (inclusive) to false.
Example:
1import { Bitwise } from "bitwise-operation"; 2 3Bitwise.mask(1, 5); // => 0b00011110 4 5Bitwise.chain(0b1011011) 6 .mask(1, 5) // => 0b00011110 7 .valueOf(); 8// Equal to: Bitwise.chain(0b1011011).and(Bitwise.mask(1, 5)).valueOf() 9 10// => 0b00011010
Bitwise.chain(value).clear([fromIndex= 0,] toIndex)
Sets the bits from the specified fromIndex (inclusive) to the specified toIndex (inclusive) to false.
Example:
1import { Bitwise } from "bitwise-operation"; 2 3Bitwise.chain(0b1011011).clear(1, 5).valueOf(); 4 5// => 0b1000001
Bitwise.chain(value).length()
Returns the "logical size" of this Bitwise: the index of the highest set bit in the Bitwise plus one.
Example:
1import { Bitwise } from "bitwise-operation"; 2 3Bitwise.chain(0b1011011).length(); 4 5// => 7
Alias: size()
Bitwise.chain(value).set(idx [, value = true])
Sets the bit at the specified index to the specified value (default true
)
Example:
1import { Bitwise } from "bitwise-operation"; 2 3Bitwise.chain(0b0001).set(2).valueOf(); 4 5// => 0b0101
Bitwise.chain(value).set(idx)
Sets the bit at the specified index to false
Example:
1import { Bitwise } from "bitwise-operation"; 2 3Bitwise.chain(0b0101).unset(0).valueOf(); 4 5// => 0b0100
Bitwise.chain(value).get(idx)
Returns the value of the bit with the specified index
Example:
1import { Bitwise } from "bitwise-operation"; 2 3Bitwise.chain(0b0001).get(0); 4 5// => true
Bitwise.toggle(value, ...idx)
Bitwise.chain(value).toggle(idx)
Sets the bit at the specified index to the complement of its current value.
Example:
1import { Bitwise } from "bitwise-operation"; 2 3Bitwise.toggle(0b0001, 1); 4 5Bitwise.chain(0b0001).toggle(1).valueOf(); 6 7// => 0b0011
Bitwise.toggle(value, ...[idx1, idx2])
Bitwise.chain(value).swap(idx1, idx2)
Swap bits to index idx1
and idx2
Example:
1import { Bitwise } from "bitwise-operation"; 2 3Bitwise.swap(0b0101, [1, 2]); 4 5Bitwise.chain(0b0101).swap(1, 2).valueOf(); 6 7// => 0b0011
Bitwise.chain(value).equals(value)
Compares this object against the specified object
Example:
1import { Bitwise } from "bitwise-operation"; 2 3Bitwise.chain(0b0101).equals(0b0111); 4 5// => false
Bitwise.chain(value).setValue(value)
Replaces the current value of the object with the new value
Example:
1import { Bitwise } from "bitwise-operation"; 2 3Bitwise.chain(0b0101).setValue(0b0111).valueOf(); 4 5// => 0b0111
Bitwise.chain(value).setRange(fromIndex, toIndex )
Sets the bits from the specified fromIndex
(inclusive) to the specified toIndex
(inclusive) to true
.
Example:
1import { Bitwise } from "bitwise-operation"; 2 3Bitwise.chain(0b0101).setRange(1, 2).valueOf(); 4 5// => 0b0111
Bitwise.chain(value).unsetRange(fromIndex, toIndex )
Sets the bits from the specified fromIndex
(inclusive) to the specified toIndex
(inclusive) to false
.
Example:
1import { Bitwise } from "bitwise-operation"; 2 3Bitwise.chain(0b0101).unsetRange(1, 2).valueOf(); 4 5// => 0b0001
Bitwise.chain(value).toggleRange(fromIndex, toIndex )
Sets each bit from the specified fromIndex (inclusive) to the specified toIndex (inclusive) to the complement of its current value.
Example:
1import { Bitwise } from "bitwise-operation"; 2 3Bitwise.chain(0b0101).toggleRange(1, 2).valueOf(); 4 5// => 0b0011
Bitwise.chain(value).copy()
Cloning this Bitwise produces a new Bitwise that is equal to it.
Example:
1import { Bitwise } from "bitwise-operation"; 2 3var a = Bitwise(0b0001); 4var b = a; 5var c = a.copy(); 6 7a.toggle(1); 8 9a.valueOf(); // => 0b0011 10b.valueOf(); // => 0b0011 11c.valueOf(); // => 0b0001
Alias: clone()
Bitwise.chain(value).valueOf()
Return the current value of this Bitwise.
Example:
1import { Bitwise } from "bitwise-operation"; 2 3Bitwise.chain(0b0101).valueOf(); 4 5// => 0b0101
Bitwise.chain(value).toString()
Bitwise.chain(value).toString(length, separator)
Returns a string representation of this Bitwise.
Example:
1import { Bitwise } from "bitwise-operation"; 2 3Bitwise.chain(0b0101).toString(); 4 5// => "0101" 6 7Bitwise.chain(571).toString(4, " "); 8 9// => "10 0011 1011"
Bitwise.chain(value).toArray()
Returns a array representation of this Bitwise.
Example:
1import { Bitwise } from "bitwise-operation";
2
3var bitwise = Bitwise(571);
4
5bitwise.toString(4, " ");
6// => "10 0011 1011"
7
8bitwise.toArray();
9// => [ 1, 1, 0, 1, 1, 1, 0, 0, 0, 1 ]
Bitwise.chain(value).cardinality()
Returns the number of bits set to true in this Bitwise.
Example:
1import { Bitwise } from "bitwise-operation"; 2 3var bitwise = Bitwise(571); 4 5bitwise.toString(4, " "); 6// => "10 0011 1011" 7 8bitwise.cardinality(); 9// => 6
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/17 approved changesets -- score normalized to 0
Reason
no SAST tool detected
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
branch protection not enabled on development/release branches
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