A small javascript utility API for working w. 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/
npm install bitflag-utils --save
var bitflagUtils = require('bitflag-utils');
- flagsToCheckFor - the flag(s) to check for against the current flag(s).
- currentFlags - the current flag(s) to check against.
boolean - true if the flag(s) were present or false otherwise.
var crntFlags = 1 << 0 | 1 << 1 | 1 << 4;
bitflagUtils.hasFlags( 1 << 1, crntFlags );//returns true;
- toAdd - the flag(s) to add to the current flag(s).
- currentFlags - the current flag(s) to add to.
number - a number value representing the current flag(s) and those added to it.
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)
- toDel - the flag(s) to remove from the current flag(s).
- currentFlags - the current flag(s) to remove from.
number - a number value representing the current flag(s) and those removed from it.
var crntFlags = 1 << 0 | 1 << 1 | 1 << 4; //19
bitflagUtils.delFlags( 1 << 1, crntFlags ); //-2
//returns 1 << 0 | 1 << 4; (or 17)