bitflag-utils

0.1.2 • Public • Published

bitflag-utils

A small javascript utility API for working w. bitflags.

understading bitflags

Check out this article I wrote back in 2012 for a better understanding of how bitflags work. http://jwopitz.wordpress.com/2012/02/13/using-bitflags-and-bitwise-math/

install

npm install bitflag-utils --save

require

var bitflagUtils = require('bitflag-utils');

APIs

hasFlags

params

  • flagsToCheckFor - the flag(s) to check for against the current flag(s).
  • currentFlags - the current flag(s) to check against.

returns

boolean - true if the flag(s) were present or false otherwise.

example

var crntFlags = 1 << 0 | 1 << 1 | 1 << 4;
bitflagUtils.hasFlags( 1 << 1, crntFlags );//returns true;

addFlags

params

  • toAdd - the flag(s) to add to the current flag(s).
  • currentFlags - the current flag(s) to add to.

returns

number - a number value representing the current flag(s) and those added to it.

example

var crntFlags = 1 << 0 | 1 << 1 | 1 << 4; //19
bitflagUtils.addFlags( 1 << 2, crntFlags ); //+4
//returns 1 << 0 | 1 << 1 | 1 << 2 | 1 << 4 (or 23)

delFlags

params

  • toDel - the flag(s) to remove from the current flag(s).
  • currentFlags - the current flag(s) to remove from.

returns

number - a number value representing the current flag(s) and those removed from it.

example

var crntFlags = 1 << 0 | 1 << 1 | 1 << 4; //19
bitflagUtils.delFlags( 1 << 1, crntFlags ); //-2
//returns 1 << 0 | 1 << 4; (or 17)

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.1.2
    2
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.1.2
    2
  • 0.1.1
    1
  • 0.1.0
    1

Package Sidebar

Install

npm i bitflag-utils

Weekly Downloads

4

Version

0.1.2

License

none

Last publish

Collaborators

  • jusopi