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;
}
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;
}
100 has a minimum of one bit set 000000 has no 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