VOOZH about

URL: https://www.geeksforgeeks.org/cpp/bitsetcount-in-c-stl/

⇱ bitset count() in C++ STL - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

bitset count() in C++ STL

Last Updated : 18 Jun, 2018
bitset::count() is an inbuilt STL in C++ which returns the number of set bits in the binary representation of a number. Syntax:
int count() 
Parameter: The function accepts no parameter. Return Value: The function returns the number of set bits. It returns the total number of ones or the number of set bits in the binary representation of the number if the passed number is an integer. Below programs illustrates the bitset::count() function. Program 1:
Output:
1100 has 2 set bit
001000 has 1 set bit
Program 2:
Output:
0000 has 0 set bit
0010 has 1 set bit
Comment