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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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;
}

chevron_right


Output:

1100 has a minimum of one bit set
000000 has no bits set

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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;
}

chevron_right


Output:

100 has a minimum of one bit set
000000 has no bits set


My Personal Notes arrow_drop_up

The function of education is to teach one to think intensively and to think critically

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.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.