From 3f963ccc21283cc03b2283868e271c7390292a7f Mon Sep 17 00:00:00 2001 From: Ujjwal Aryal <26333842+UjjwalAryal@users.noreply.github.com> Date: Fri, 10 Aug 2018 20:46:39 +0530 Subject: [PATCH] Update README.md (#141) --- src/algorithms/math/bits/README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/algorithms/math/bits/README.md b/src/algorithms/math/bits/README.md index 5d25efe5..d921f8ea 100644 --- a/src/algorithms/math/bits/README.md +++ b/src/algorithms/math/bits/README.md @@ -91,6 +91,25 @@ inverting all of the bits of the number and adding 1 to it. > See `switchSign` function for further details. +#### Multiply + +This method multiplies two numbers(integer) using bitwise operators. This method is based on that "Every number can be denoted as the sum of powers of 2". + +``` +Let us take two numbers number1 and number2. + +number1 * number2 = number1 * (Representation in Base 2) + +Let us take number2 = 8 = 0b 1000 + +number1 * number2 = number1 * (1*8 + 0*4 + 0*2 + 0*1) + = number1 * 1 * (1<<3) + number1 * 0 * (1<<2) + number1 * 0 * (1<<1) + number1 * 0 * (1<<0) + = (number1<<3) * 1 + (number1<<2) * 0 + (number1<<1) * 0 + (number1<<0) * 0 +``` + + +> See `multiply` function for further details. + ## References - [Bit Manipulation on YouTube](https://www.youtube.com/watch?v=NLKQEOgBAnw&t=0s&index=28&list=PLLXdhg_r2hKA7DPDsunoDZ-Z769jWn4R8)