bits

Easy bit manipulation

npm install bits
19 downloads in the last month

bits

Build Status Dependency Status NPM version

Usage

If you're using Node.js type:

npm install --save bits

Then load the module:

var bits = require("bits");

If you'd like to use it in your browser application, just link the JS file:

<script src="bits.js"></script>

You can also use script loaders like require.js:

define(["./bits"], function(bits){ /* .. */ });

Now here is the API:

var data = 0;
data = bits.set(data, 2);
data = bits.set(data, [0,3,7]); // set bit 0, 3 and 7
data = bits.clear(data, 1);
data = bits.clear(data, 1, 5);  // clear bit 1,3,4,5
data = bits.toggle(data, 5);
data = bits.test(data, 6);      // returns true or false
data = bits.get(data, 6);       // returns 0 or 1

Test

npm test

License

MIT license

npm loves you