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++
#include <bits/stdc++.h>
using namespace std;
int main()
{
bitset<4> b1(string( "1100" ));
bitset<6> b2(string( "000000" ));
bool result1 = b1.none();
if (result1)
cout << b1 << " has no bits set"
<< endl;
else
cout << b1 << " has a minimum of one bit set"
<< endl;
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++
#include <bits/stdc++.h>
using namespace std;
int main()
{
bitset<3> b1(4);
bitset<6> b2(0);
bool result1 = b1.none();
if (result1)
cout << b1 << " has no bits set"
<< endl;
else
cout << b1 << " has a minimum of one bit set"
<< endl;
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
Share your thoughts in the comments
Please Login to comment...