mirror of
https://github.com/trekhleb/javascript-algorithms.git
synced 2026-03-13 08:51:02 +08:00
Add bitsDiff function.
This commit is contained in:
@@ -91,20 +91,6 @@ inverting all of the bits of the number and adding 1 to it.
|
||||
|
||||
> See `switchSign` function for further details.
|
||||
|
||||
#### Count Bits to Flip One Number to Another
|
||||
|
||||
This methods outputs the number of bits required to convert a number to another. This
|
||||
makes use of property that when numbers are XORed the result will be number of different
|
||||
bits and `countSetBits`.
|
||||
|
||||
``
|
||||
Number A : 5 = (0101)_2
|
||||
Number B : 1 = (0001)_2
|
||||
Count Bits to be Flipped: 1
|
||||
``
|
||||
|
||||
> See `countBitsToflipAToB` function for further details.
|
||||
|
||||
#### Multiply Two Numbers
|
||||
|
||||
This method multiplies two integer numbers using bitwise operators.
|
||||
@@ -143,6 +129,19 @@ Count of set bits = 2
|
||||
|
||||
> See `countSetBits` function for further details.
|
||||
|
||||
#### Count Bits to Flip One Number to Another
|
||||
|
||||
This methods outputs the number of bits required to convert one number to another.
|
||||
This makes use of property that when numbers are `XOR`-ed the result will be number
|
||||
of different bits.
|
||||
|
||||
```
|
||||
5 = 0b0101
|
||||
1 = 0b0001
|
||||
Count of Bits to be Flipped: 1
|
||||
```
|
||||
|
||||
> See `bitsDiff` function for further details.
|
||||
|
||||
## References
|
||||
|
||||
|
||||
Reference in New Issue
Block a user