menu
techminis

A naukri.com initiative

google-web-stories
Home

>

Programming News

>

Count the ...
source image

Prodevelopertutorial

1M

read

72

img
dot

Count the number of set bits

  • The given problem is to count the number of set bits in a given number when represented in binary format.
  • Two methods to solve this problem are by using the inbuilt library function and by using bit manipulation.
  • The first method makes use of the bitset<32>() function in C++ to convert the number to binary and then uses the count() method to find the number of set bits.
  • The second method involves using bitwise and (&) and right shift (>>) operations to check and count the set bits.

Read Full Article

like

4 Likes

For uninterrupted reading, download the app