Socket
Book a DemoInstallSign in
Socket

bitwise-buffer

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bitwise-buffer

A simple module for bitwise operations on buffers.

1.0.2
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

buffer-bitwise

travis npm downloads javascript style guide

A simple module for bitwise operations on buffers.

Install

npm i buffer-bitwise

Example

const bitwiseBuffer = require('bitwise-buffer')
const { xor, and, or, nor, not, leftShift, rightShift, lshift, rshift } = bitwiseBuffer

const a = Buffer.from('0f0f', 'hex')
const b = Buffer.from('ff00', 'hex')

xor(a, b).toString('hex') // 'f00f'
or(a, b).toString('hex') // 'ff0f'
and(a, b).toString('hex') // '0f00'
nor(a, b).toString('hex') // '00f0'
not(a).toString('hex') // 'f0f0'

leftShift(a, 4).toString('hex') // 'f0f0'
rightShift(a, 4).toString('hex') // '00f0'

// for shift operator you can chose to fill with 1
leftShift(a, 4, 1).toString('hex') // 'f0ff'

// lshift is an alias of leftShift
lshift === leftShift // true

// rshift is an alias of rightShift
rshift === rightShift // true

// for binary operator when operand length are differents
const c = Buffer.from('ff00fff0f', 'hex')

xor(a, c).toString('hex') // 'f00ffff0f'
xor(c, a).toString('hex') // 'f00ffff0f'

// all operator allocate new buffer
// for mutable operator use operator.mut
const d = not.mut(a)
a === d // true
a.toString('hex') // 'f0f0'

// for binary operator
const e = Buffer.from('0ff0', 'hex')
const f = Buffer.from('f0f0ff0f00', 'hex')

const g = xor.mut(e, f)
g === e // true
e.toString('hex') // 'ff00'

// #method.mut is an alias of #mut.method

bitwiseBuffer.xor.mut === bitwiseBuffer.mut.xor // true

License

MIT

Keywords

bits

FAQs

Package last updated on 18 May 2019

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

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.