1.0.3 • Published 4 years ago

gbit v1.0.3

Weekly downloads
2
License
ISC
Repository
github
Last release
4 years ago

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

10100
42

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)
1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

5 years ago

1.0.0

5 years ago