mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-19 01:55:51 +08:00
18 lines
446 B
JavaScript
18 lines
446 B
JavaScript
/*
|
|
author: vivek9patel
|
|
license: GPL-3.0 or later
|
|
|
|
This script will find number of 1's
|
|
in binary representation of given number
|
|
|
|
*/
|
|
|
|
function BinaryCountSetBits (a) {
|
|
'use strict'
|
|
// convert number into binary representation and return number of set bits in binary representation
|
|
return a.toString(2).split('1').length - 1
|
|
}
|
|
|
|
// Run `binary_and` Function to find the binary and operation
|
|
console.log(BinaryCountSetBits(251))
|