Skip to content
Related Articles

Related Articles

bitset none() in C++ STL
  • Last Updated : 12 Nov, 2020

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 none() 

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:  

C++




// C++ 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;
}
Output: 
1100 has a minimum of one bit set
000000 has no bits set




 

Program 2:  

C++




// C++ 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;
}
Output: 
100 has a minimum of one bit set
000000 has no bits set




 

Want to learn from the best curated videos and practice problems, check out the C++ Foundation Course for Basic to Advanced C++ and C++ STL Course for foundation plus STL.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.
My Personal Notes arrow_drop_up
Recommended Articles
Page :