From 53c7143e07f52c831e57aef83a8cb294209bfe09 Mon Sep 17 00:00:00 2001 From: Ujjwal Aryal <26333842+UjjwalAryal@users.noreply.github.com> Date: Fri, 10 Aug 2018 20:09:45 +0530 Subject: [PATCH] Create multiply.js (#140) Multiply Two numbers using Bit-wise Operator. --- src/algorithms/math/bits/multiply.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/algorithms/math/bits/multiply.js diff --git a/src/algorithms/math/bits/multiply.js b/src/algorithms/math/bits/multiply.js new file mode 100644 index 00000000..8755d6be --- /dev/null +++ b/src/algorithms/math/bits/multiply.js @@ -0,0 +1,14 @@ +/** + * @param {number, number} + * @return {number} + */ +export default function multiply(number1, number2) { + var c = 0, result = 0; + while(number2){ + if(number2&1) + result += (number1 << c); + c += 1; + number2 >>= 1; + } + return result; +}