Count Set Bits
BIT MANIPULATION
Problem
Given a positive integer n
, calculate the number of set bits, which are the 1s present in its binary format.
Examples
countSetBits(5) // return 2 // Why? 5 in binary is 101 countSetBits(15) // return 4 // Why? 15 in binary is 1111
Loading...
Loading...Loading...