mirror of
https://github.com/trekhleb/javascript-algorithms.git
synced 2025-07-15 08:32:24 +08:00
Add countSetBits (#152)
This commit is contained in:

committed by
Oleksii Trekhleb

parent
28ee030a82
commit
a8f7d6a333
@ -116,6 +116,17 @@ by `4` bits (`x << 4`).
|
||||
|
||||
> See `multiplyUnsigned` function for further details.
|
||||
|
||||
#### Count Set Bits
|
||||
|
||||
This method counts the number of set bits in a number using bitwise operators.
|
||||
|
||||
``
|
||||
Number: 5 = (0101)_2
|
||||
Count Set Bits = 2
|
||||
``
|
||||
|
||||
> See `countSetBits` function for further details.
|
||||
|
||||
## References
|
||||
|
||||
- [Bit Manipulation on YouTube](https://www.youtube.com/watch?v=NLKQEOgBAnw&t=0s&index=28&list=PLLXdhg_r2hKA7DPDsunoDZ-Z769jWn4R8)
|
||||
|
Reference in New Issue
Block a user