2020-10-01 13:12:20 +05:30
|
|
|
/*
|
|
|
|
|
author: vivek9patel
|
|
|
|
|
license: GPL-3.0 or later
|
|
|
|
|
|
|
|
|
|
This script will find number of 1's
|
|
|
|
|
in binary representain of given number
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
2020-10-01 13:29:41 +05:30
|
|
|
function BinaryCountSetBits (a) {
|
|
|
|
|
'use strict'
|
|
|
|
|
// convert number into binary representation and return number of set bits in binary representaion
|
|
|
|
|
return a.toString(2).split('1').length - 1
|
2020-10-01 13:12:20 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Run `binary_and` Function to find the binary and operation
|
2020-10-01 13:29:41 +05:30
|
|
|
console.log(BinaryCountSetBits(251))
|