public member function
<bitset>
std::bitset::anybool any() const noexcept;
Test if any bit is set
Returns whether any of the bits is set (i.e., whether at least one bit in the bitset is set to one).This is the opposite of bitset::none.
true
if any of the bits in the bitset is set (to one), and false
otherwise.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// bitset::any
#include <iostream> // std::cin, std::cout
#include <bitset> // std::bitset
int main ()
{
std::bitset<16> foo;
std::cout << "Please, enter a binary number: ";
std::cin >> foo;
if (foo.any())
std::cout << foo << " has " << foo.count() << " bits set.\n";
else
std::cout << foo << " has no bits set.\n";
return 0;
}
Please, enter a binary number: 10110 0000000000010110 has 3 bits set.
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