math-uint8-bits

1.0.0 • Public • Published

Bits

NPM version Build Status Coverage Status Dependencies

Returns a string giving the literal bit representation of an unsigned 8-bit integer.

Installation

$ npm install math-uint8-bits

Usage

var bits = require( 'math-uint8-bits' );

bits( x )

Returns a string giving the literal bit representation of an unsigned 8-bit integer.

var a = new Uint8Array( [ 1, 4, 9 ] );
 
var str = bits( a[0] );
// returns '00000001'
 
str = bits( a[1] );
// returns '00000100'
 
str = bits( a[2] );
// returns '00001001'

Notes

Examples

var MAX_UINT8 = require( 'const-max-uint8' );
var bits = require( 'math-uint8-bits' );
 
var x;
var y;
var b;
var i;
 
= new Uint8Array( MAX_UINT8+1 );
for ( i = 0; i < x.length; i++ ) {
    x[ i ] = i;
}
 
// Convert unsigned 8-bit integers to literal bit representations...
for ( i = 0; i < x.length; i++ ) {
    b = bits( x[i] );
    y = parseInt( b, 2 );
    console.log( 'x: %d, b: %s, y: %d', x[i], b, y );
}

To run the example code from the top-level application directory,

$ node ./examples/index.js

Tests

Unit

This repository uses tape for unit tests. To run the tests, execute the following command in the top-level application directory:

$ make test

All new feature development should have corresponding unit tests to validate correct functionality.

Test Coverage

This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:

$ make test-cov

Istanbul creates a ./reports/coverage directory. To access an HTML version of the report,

$ make view-cov

Browser Support

This repository uses Testling for browser testing. To run the tests in a (headless) local web browser, execute the following command in the top-level application directory:

$ make test-browsers

To view the tests in a local web browser,

$ make view-browser-tests

License

MIT license.

Copyright

Copyright © 2016. The Compute.io Authors.

Package Sidebar

Install

npm i math-uint8-bits

Weekly Downloads

1

Version

1.0.0

License

MIT

Last publish

Collaborators

  • kgryte