bitwise.js

1.0.6 • Public • Published

bitwise.js

Badge LICENSE Node npm version

A utility for bitwise operations that supports both number and bigint types in JavaScript/TypeScript.

Installation

npm install bitwise.js --save

Usage

Example:

import { bitwise } from "bitwise.js";

console.log(bitwise.and(5, 3n)); // => 1n (5 & 3n)
console.log(bitwise.or(2.7, 3)); // => 3 (2 | 3)
console.log(bitwise.xor(5, 3)); // => 6 (5 ^ 3)
console.log(bitwise.not(5)); // => -6 (~5)
console.log(bitwise.leftShift(3.9, 2)); // => 12 (3 << 2)
console.log(bitwise.rightShift(5n, 1)); // => 2n (5n >> 1)

Methods

  • and(a, b, prefer = 'bigint'): Performs bitwise AND on a and b.
  • or(a, b, prefer = 'bigint'): Performs bitwise OR on a and b.
  • xor(a, b, prefer = 'bigint'): Performs bitwise XOR on a and b.
  • not(a): Performs bitwise NOT on a.
  • leftShift(a, bits = 1): Performs a left shift operation on a.
  • rightShift(a, bits = 1): Performs a right shift operation on a.
  • zeroFillRightShift(a, bits = 1): Performs an unsigned right shift on a (only works with numbers).

License

The Anti 996 License

Readme

Keywords

Package Sidebar

Install

npm i bitwise.js

Weekly Downloads

2

Version

1.0.6

License

SEE LICENSE IN LICENSE

Unpacked Size

50.6 kB

Total Files

9

Last publish

Collaborators

  • axetroy