bitset size() in C++ STL Last Updated : 16 Jun, 2021 Comments Improve Suggest changes Like Article Like Report bitset::size() is a built-in STL in C++ which returns the total number of bits. Syntax: bitset_name.size() Parameter: The function accepts no parameter. Return Value: The function returns an integral value which signifies the number of bits. It eventually returns the size that has been given while initializing the bitset. Below programs illustrate the bitset::size() function. Program 1: C++ // C++ program to illustrate the // bitset::size() function // when input is a string #include <bits/stdc++.h> using namespace std; int main() { // initialization of the bitset string bitset<4> b1(string("1100")); bitset<6> b2(string("010010")); // prints the size i.e., // the number of bits in "1100" cout << "The number of bits in " << b1 << " is " << b1.size() << endl; // prints the size i.e., // the number of bits in "010010" cout << "The number of bits in " << b2 << " is " << b2.size() << endl; return 0; } Output: The number of bits in 1100 is 4 The number of bits in 010010 is 6 Program 2: C++ // C++ program to illustrate the // bitset::size() function // when input is a number #include <bits/stdc++.h> using namespace std; int main() { // initialization of the bitset string bitset<3> b1(5); bitset<5> b2(17); // prints the size i.e., // the number of bits in 5 cout << "The number of bits in " << b1 << " is " << b1.size() << endl; // prints the size i.e., // the number of bits in 17 cout << "The number of bits in " << b2 << " is " << b2.size() << endl; return 0; } Output: The number of bits in 101 is 3 The number of bits in 10001 is 5 Comment More infoAdvertise with us Next Article bitset size() in C++ STL G gopaldave Follow Improve Article Tags : Misc C++ STL CPP-Functions CPP-bitset +1 More Practice Tags : CPPMiscSTL Similar Reads 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 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 s 2 min read bitset::flip() in C++ STL bitset::flip() is a built-in STL in C++ which flips the bits. If no parameter is passed in the function, then it flips all the bit values converting zeros to ones and ones to zeros. If a parameter position is passed, it flips the bit at the position only. Syntax: bitset_name.flip(int pos) Parameter: 2 min read bitset any() in C++ STL The bitset::any() is an inbuilt function in C++ STL which returns True if at least one bit is set in a number. It returns False if all the bits are not set or if the number is zero. Syntax: bool any() Parameter: The function does not accepts any parameter. Return Value: The function returns a boolea 2 min read bitset operator[] in C++ STL bitset::operator[] is a built-in function in C++ STL which is used to assign value to any index of a bitset. Syntax: bitset_operator[index] = value Parameter: The parameter index specifies the position at which the value is to be assigned. Return Value: The function returns the value to the bit at t 2 min read bitset set() function in C++ STL bitset::set() is a built-in STL in C++ which sets the bit to a given value at a particular index. If no parameter is passed, it sets all bits to 1. If only a single parameter is passed, it sets the bit at that particular index to 1. Syntax: set(int index, bool val) Parameter: The function accepts tw 2 min read Like