bitset::count() is an inbuilt STL in C++ which returns the number of set bits in the binary representation of a number.
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.
1100 has 2 set bit 001000 has 1 set bit
0000 has 0 set bit 0010 has 1 set bit
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Count number of set bits in a range using bitset
- Count number of common elements between two arrays by using Bitset and Bitwise operation
- std::bitset::to_ullong and std::bitset::to_ulong in C++ STL
- bitset any() in C++ STL
- bitset none() in C++ STL
- bitset test() in C++ STL
- bitset operator in C++ STL
- C++ bitset and its application
- bitset::flip() in C++ STL
- bitset size() in C++ STL
- bitset all() function in C++ STL
- bitset set() function in C++ STL
- C++ bitset interesting facts
- Subset sum queries using bitset
- bitset reset() function in C++ STL
- _Find_next() function in C++ bitset with Examples
- _Find_first() function in C++ bitset with Examples
- std::count() in C++ STL
- map count() function in C++ STL
- unordered_map count() in C++
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.