public member function
<bitset>
std::bitset::countsize_t count() const noexcept;
Count bits set
Returns the number of bits in the bitset that are set (i.e., that have a value of one).For the total number of bits in the bitset (including both zeros and ones), see bitset::size.
size_t is an unsigned integral type.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// bitset::count
#include <iostream> // std::cout
#include <string> // std::string
#include <bitset> // std::bitset
int main ()
{
std::bitset<8> foo (std::string("10110011"));
std::cout << foo << " has ";
std::cout << foo.count() << " ones and ";
std::cout << (foo.size()-foo.count()) << " zeros.\n";
return 0;
}
10110011 has 5 ones and 3 zeros.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4