File tree 2 files changed +26
-0
lines changed
2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -91,6 +91,20 @@ inverting all of the bits of the number and adding 1 to it.
91
91
92
92
> See ` switchSign ` function for further details.
93
93
94
+ #### Count Bits to Flip One Number to Another
95
+
96
+ This methods outputs the number of bits required to convert a number to another. This
97
+ makes use of property that when numbers are XORed the result will be number of different
98
+ bits and ` countSetBits ` .
99
+
100
+ ``
101
+ Number A : 5 = (0101)_ 2
102
+ Number B : 1 = (0001)_ 2
103
+ Count Bits to be Flipped: 1
104
+ ``
105
+
106
+ > See ` countBitsToflipAToB ` function for further details.
107
+
94
108
#### Multiply Two Numbers
95
109
96
110
This method multiplies two integer numbers using bitwise operators.
@@ -129,6 +143,7 @@ Count of set bits = 2
129
143
130
144
> See ` countSetBits ` function for further details.
131
145
146
+
132
147
## References
133
148
134
149
- [ Bit Manipulation on YouTube] ( https://www.youtube.com/watch?v=NLKQEOgBAnw&t=0s&index=28&list=PLLXdhg_r2hKA7DPDsunoDZ-Z769jWn4R8 )
Original file line number Diff line number Diff line change
1
+ import countSetBits from 'countSetBits' ;
2
+
3
+ /**
4
+ * @param {number } number
5
+ * @return {number }
6
+ */
7
+ export default function countBitsToflipAToB ( numberA , numberB ) {
8
+
9
+ return countSetBits ( numberA ^ numberB ) ;
10
+
11
+ }
You can’t perform that action at this time.
0 commit comments