8000 Update bit-manipulation.md · cp-algorithms/cp-algorithms@2b23aff · GitHub
[go: up one dir, main page]

Skip to content

Commit 2b23aff

Browse files
Update bit-manipulation.md
1 parent dff3db3 commit 2b23aff

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

src/algebra/bit-manipulation.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,8 @@ With the new knowledge in hand we can come up with the following algorithm:
208208
209209
- Find the highest power of $2$ that is lesser than or equal to the given number. Let this number be $x$.
210210
- Calculate the number of set bits from $1$ to $2^x - 1$ by using the formua $x \cdot 2^{x-1}$.
211-
212-
The next steps needs more explanation.
213-
214211
- Count the no. of set bits in the most significant bit from $2^x$ to $n$ and add it.
215-
- Subtract $2^x$ from $n$ and Recurse with the algorithm using the new $n$.
212+
- Subtract $2^x$ from $n$ and repeat the above steps using the new $n$.
216213
217214
```cpp
218215
int countSetBits(int n) {

0 commit comments

Comments
 (0)
0