Skip to content

Commit 7f18949

Browse files
committedAug 10, 2018
Update BitWise Operation README.
1 parent 3f963cc commit 7f18949

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed
 

‎src/algorithms/math/bits/README.md

+16-10
Original file line numberDiff line numberDiff line change
@@ -91,24 +91,30 @@ inverting all of the bits of the number and adding 1 to it.
9191

9292
> See `switchSign` function for further details.
9393
94-
#### Multiply
94+
#### Multiply Two Numbers
9595

96-
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".
96+
This method multiplies two integer numbers using bitwise operators.
97+
This method is based on that "Every number can be denoted as the sum of powers of 2".
9798

98-
```
99-
Let us take two numbers number1 and number2.
99+
The main idea of bitwise multiplication is that every number may be split
100+
to the sum of powers of two:
101+
102+
I.e.
100103

101-
number1 * number2 = number1 * (Representation in Base 2)
104+
```text
105+
19 = 2^4 + 2^1 + 2^0
106+
```
102107

103-
Let us take number2 = 8 = 0b 1000
108+
Then multiplying number `x` by `19` is equivalent of:
104109

105-
number1 * number2 = number1 * (1*8 + 0*4 + 0*2 + 0*1)
106-
= number1 * 1 * (1<<3) + number1 * 0 * (1<<2) + number1 * 0 * (1<<1) + number1 * 0 * (1<<0)
107-
= (number1<<3) * 1 + (number1<<2) * 0 + (number1<<1) * 0 + (number1<<0) * 0
110+
```text
111+
x * 19 = x * 2^4 + x * 2^1 + x * 2^0
108112
```
109113

114+
Now we need to remember that `x * 2^4` is equivalent of shifting `x` left
115+
by `4` bits ()`x << 4`).
110116

111-
> See `multiply` function for further details.
117+
> See `multiplyUnsigned` function for further details.
112118
113119
## References
114120

‎src/algorithms/math/bits/multiplyUnsigned.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Multiply to unsigned numbers using bitwise operator.
33
*
44
* The main idea of bitwise multiplication is that every number may be split
5-
* to the sum of posers of two:
5+
* to the sum of powers of two:
66
*
77
* I.e. 19 = 2^4 + 2^1 + 2^0
88
*

0 commit comments

Comments
 (0)
Please sign in to comment.