Easy bit manipulation
CoffeeScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
.npmignore
.travis.yml
README.md
bits.coffee
bits.js
bits.spec.coffee
bower.json
package.json

README.md

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, download it manually or use bower:

bower install bits

...and then 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