gbit
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

build

Instruction

This package is find the value of 1 in the binary representation of an integer number

Install

  npm i gbit

Usage

    const gbit = require('gbit');
    gbit(20); 

Examples

    gbit(20);  

output [2,4]

20->10100

1 0 1 0 0
4 2

Perfermance

function defaultGetKeys(num){
    let nStr = Number(num).toString(2);
    let keys = [],len = nStr.length;
    for(let i =0;i<len;i++){
        nStr[i] === '1' && keys.push(len-1-i)
    }
    return keys;
}    
 
let start = Date.now();
for(let i=0;i<10000000;i++){
    defaultGetKeys(66666666); // 9596ms
    getKeys(66666666); // 4596ms fast
}
let stop = Date.now();
console.log(stop-start)

Readme

Keywords

Package Sidebar

Install

npm i gbit

Weekly Downloads

0

Version

1.0.3

License

ISC

Unpacked Size

3.16 kB

Total Files

7

Last publish

Collaborators

  • zshtail