bitset none() in C++ STL
bitset::none() is a built-in STL in C++ which returns True if none of its bits are set. It returns False if a minimum of one bit is set.
Syntax:
bool count()
Parameter: The function accepts no parameter.
Return Value: The function returns a boolean. The boolean value is True if none of its bits are set. It is False if at least one bit is set.
Below programs illustrates the bitset::none() function.
Program 1:
// CPP program to illustrate the // bitset::none() function #include <bits/stdc++.h> using namespace std; int main() { // initialization of bitset bitset<4> b1(string("1100")); bitset<6> b2(string("000000")); // Function to check if none of // the bits are set or not in b1 bool result1 = b1.none(); if (result1) cout << b1 << " has no bits set" << endl; else cout << b1 << " has a minimum of one bit set" << endl; // Function to check if none of // the bits are set or not in b1 bool result2 = b2.none(); if (result2) cout << b2 << " has no bits set" << endl; else cout << b2 << " has a minimum of one bit set" << endl; return 0; } |
1100 has a minimum of one bit set 000000 has no bits set
Program 2:
// CPP program to illustrate the // bitset::none() function // when the input is a number #include <bits/stdc++.h> using namespace std; int main() { // initialization of bitset bitset<3> b1(4); bitset<6> b2(0); // Function to check if none of // the bits are set or not in b1 bool result1 = b1.none(); if (result1) cout << b1 << " has no bits set" << endl; else cout << b1 << " has a minimum of one bit set" << endl; // Function to check if none of // the bits are set or not in b1 bool result2 = b2.none(); if (result2) cout << b2 << " has no bits set" << endl; else cout << b2 << " has a minimum of one bit set" << endl; return 0; } |
100 has a minimum of one bit set 000000 has no bits set
Recommended Posts:
- std::bitset::to_ullong and std::bitset::to_ulong in C++ STL
- bitset any() in C++ STL
- bitset set() function in C++ STL
- bitset all() function in C++ STL
- bitset operator[] in C++ STL
- bitset test() in C++ STL
- C++ bitset and its application
- bitset size() in C++ STL
- bitset::flip() in C++ STL
- bitset count() in C++ STL
- C++ bitset interesting facts
- Subset sum queries using bitset
- bitset reset() function in C++ STL
- Count number of set bits in a range using bitset
- Count number of common elements between two arrays by using Bitset and Bitwise operation
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.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.



