mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-12-26 15:11:16 +08:00
Add bit counter function.
This commit is contained in:
parent
9ce137cef8
commit
37c7be15e9
@ -122,10 +122,10 @@ This method counts the number of set bits in a number using bitwise operators.
|
|||||||
The main idea is that we shift the number right by one bit at a time and check
|
The main idea is that we shift the number right by one bit at a time and check
|
||||||
the result of `&` operation that is `1` if bit is set and `0` otherwise.
|
the result of `&` operation that is `1` if bit is set and `0` otherwise.
|
||||||
|
|
||||||
``
|
```text
|
||||||
Number: 5 = 0b0101
|
Number: 5 = 0b0101
|
||||||
Count of set bits = 2
|
Count of set bits = 2
|
||||||
``
|
```
|
||||||
|
|
||||||
> See `countSetBits` function for further details.
|
> See `countSetBits` function for further details.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user