bitset::all() फंक्शन क्या है?
bitset::all() C++ STL (स्टैंडर्ड टेम्पलेट लाइब्रेरी) का एक इनबिल्ट फंक्शन है। यह फंक्शन एक बूलियन मान लौटाता है। यदि कॉलिंग बिटसेट के सभी बिट्स 1 हैं तो रिटर्न मान true होता है, अन्यथा यह false लौटाता है।
यह फंक्शन कोई पैरामीटर स्वीकार नहीं करता और एक बूलियन मान लौटाता है।
सिंटैक्स
bool bitset_name.all()
उदाहरण
#include <bits/stdc++.h>
using namespace std;
void printer(bool val) {
if(val) {
cout << "The bitset has all bits set" << endl;
} else {
cout << "The bitset does not have all bits set" << endl;
}
}
int main() {
bitset<4> bit1(string("1011"));
bitset<6> bit2(string("111111"));
cout << "The bitset is " << bit1 << endl;
printer(bit1.all());
cout << "The bitset is " << bit2 << endl;
printer(bit2.all());
return 0;
}
आउटपुट
The bitset is 1011 The bitset does not have all bits set The bitset is 111111 The bitset has all bits set
व्याख्या
bit1 = 1011- सभी बिट्स 1 नहीं हैं (दूसरा बिट 0 है), इसलिएall()false लौटाता हैbit2 = 111111- सभी बिट्स 1 हैं, इसलिएall()true लौटाता है
अन्य उपयोगी bitset फंक्शन्स
| फंक्शन | विवरण |
|---|---|
any() |
true यदि कम से कम एक बिट सेट है |
none() |
true यदि कोई बिट सेट नहीं है |
count() |
सेट बिट्स की संख्या लौटाता है |
test(pos) |
विशिष्ट स्थिति पर बिट जांचता है |
set() |
सभी बिट्स सेट करता है |
reset() |
सभी बिट्स क्लियर करता है |
flip() |
सभी बिट्स फ्लिप करता है |
उपयोग का उदाहरण
bitset<8> flags("11111111");
if (flags.all()) {
cout << "सभी फ्लैग्स सेट हैं";
}
bitset<8> empty;
if (empty.none()) {
cout << "कोई फ्लैग सेट नहीं है";
}