From cc21081531fa8d6fd4e4a14f6e5d0f59aa99c05b Mon Sep 17 00:00:00 2001 From: Vivek Patel Date: Thu, 1 Oct 2020 13:12:20 +0530 Subject: [PATCH 1/3] added bit_manipulation folder & binary_count_setbits.js file --- Bit-Manipulation/binary_count_setbits.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Bit-Manipulation/binary_count_setbits.js diff --git a/Bit-Manipulation/binary_count_setbits.js b/Bit-Manipulation/binary_count_setbits.js new file mode 100644 index 000000000..7654eb6b9 --- /dev/null +++ b/Bit-Manipulation/binary_count_setbits.js @@ -0,0 +1,20 @@ +/* + author: vivek9patel + license: GPL-3.0 or later + + This script will find number of 1's + in binary representain of given number + +*/ + +function binary_count_setbits(a) { + "use strict" + // convert number into binary representation + let binA = a.toString(2) + + // return number of set bits in binary representaion + return binA.split("1").length - 1 +} + +// Run `binary_and` Function to find the binary and operation +console.log(binary_count_setbits(251)) From ca1f5385da4a725ec74052df95efc494b6de5552 Mon Sep 17 00:00:00 2001 From: Vivek Patel Date: Thu, 1 Oct 2020 13:14:58 +0530 Subject: [PATCH 2/3] renamed file --- .../{binary_count_setbits.js => BinaryCountSetBits.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Bit-Manipulation/{binary_count_setbits.js => BinaryCountSetBits.js} (100%) diff --git a/Bit-Manipulation/binary_count_setbits.js b/Bit-Manipulation/BinaryCountSetBits.js similarity index 100% rename from Bit-Manipulation/binary_count_setbits.js rename to Bit-Manipulation/BinaryCountSetBits.js From 89f5def29a13b5b78785882b783463843c4f776c Mon Sep 17 00:00:00 2001 From: Vivek Patel Date: Thu, 1 Oct 2020 13:29:41 +0530 Subject: [PATCH 3/3] updated file by JS standard --- Bit-Manipulation/BinaryCountSetBits.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/Bit-Manipulation/BinaryCountSetBits.js b/Bit-Manipulation/BinaryCountSetBits.js index 7654eb6b9..bb16afe94 100644 --- a/Bit-Manipulation/BinaryCountSetBits.js +++ b/Bit-Manipulation/BinaryCountSetBits.js @@ -7,14 +7,11 @@ */ -function binary_count_setbits(a) { - "use strict" - // convert number into binary representation - let binA = a.toString(2) - - // return number of set bits in binary representaion - return binA.split("1").length - 1 +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 } // Run `binary_and` Function to find the binary and operation -console.log(binary_count_setbits(251)) +console.log(BinaryCountSetBits(251))