🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

bitmaskjs

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bitmaskjs

A small package to convert integers to bit arrays and back, with some utilities

latest
npmnpm
Version
0.1.2
Version published
Maintainers
1
Created
Source

#Bitmask.js A small package to convert integers to bit arrays and back, with some utilities

##Installation Install with bower install bitmask, then add the bitmask.min.js script to your page. If you're using NodeJS, you can require it instead!

##Usage Create a Bitmask object by passing either an integer value or a bit array to the constructor:

// Either
var myBitmask = new Bitmask(15);

// Or
var myBitmask = new Bitmask([1,1,1,1])

The constructor also accepts a second parameter that allows you to specifiy the padding (the length of the bit array). This value defaults to 8.

At any point you can retrieve the current value in its integer or array form, regardless of how you called the constructor, by using:

myBitmask.getInteger() 	// 15
myBitmask.getBits()		// [1,1,1,1,0,0,0,0]

##Instance Methods

  • getInteger() - returns the integer value of the current instance
  • getBits() - returns the bit array representation of the current instance
  • hasBit(index) - returns true if the bit at the specified index is set
  • setBit(index, value) - sets the bit at the specified index to value (true or false)
  • toggleBit(index) - toggles the bit at the specified index
  • lShift(n) - shifts the bit array to the left by n positions (default is 1)
  • rShift(n) - shifts the bit array to the right by n positions (default is 1)

The following methods are chainable: setBit, toggleBit, lShift, rShift.

##Contributing You can edit the source in src/bitmask.js and build it using grunt. Remember to do an npm install beforehand to install all the dev dependencies!

Keywords

bitmask

FAQs

Package last updated on 19 Mar 2015

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