Add bit counter function.

This commit is contained in:
Oleksii Trekhleb 2018-08-12 10:18:32 +03:00
parent 9ce137cef8
commit 37c7be15e9

View File

@ -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.