bitset test() in C++ STL Last Updated : 08 May, 2023 Comments Improve Suggest changes Like Article Like Report bitset::test() is an inbuilt function in C++ STL which tests whether the bit at a given index is set or not. Syntax: bitset_name.test(index) Parameters: The function accepts only a single mandatory parameter index which specifies the index at which the bit is set or not. Return Value: The function returns a boolean value. It returns true if the bit at the given index is set else it returns false. Below programs illustrate the above function: Program 1: CPP // CPP program to illustrate the // bitset::test() function // when bitset is a string #include <bits/stdc++.h> using namespace std; int main() { // Initialization of bitset bitset<4> b1(string("1100")); bitset<6> b2(string("010010")); // Function to check if 2nd index bit // is set or not in b1 if (b1.test(2)) cout << "Bit at index 2 of 1100 is set\n"; else cout << "Bit at index 2 is not set\n"; // Function to check if 3rd index bit // is set or not in b2 if (b2.test(3)) cout << "Bit at index 3 of 010010 is set\n"; else cout << "Bit at index 3 of 010010 is not set\n"; return 0; } Output:Bit at index 2 of 1100 is set Bit at index 3 of 010010 is not set Program 2: CPP // CPP program to illustrate the // bitset::test() function // when the bitset is a number #include <bits/stdc++.h> using namespace std; int main() { // Initialization of bitset bitset<4> b1(5); bitset<6> b2(16); // Function to check if 2nd index bit // is set or not in b1 if (b1.test(2)) cout << "Bit at index 2 of 5 is set\n"; else cout << "Bit at index 2 of 5 is not set\n"; // Function to check if 3rd index bit // is set or not in b2 if (b2.test(3)) cout << "Bit at index 3 of 16 is set\n"; else cout << "Bit at index 3 of 16 is not set\n"; return 0; } Output:Bit at index 2 of 5 is set Bit at index 3 of 16 is not set Comment More infoAdvertise with us Next Article bitset test() in C++ STL G gopaldave Follow Improve Article Tags : C++ Programs STL CPP-Functions CPP-bitset Practice Tags : STL Similar Reads bitset count() in C++ STL bitset::count() is an inbuilt STL in C++ which returns the number of set bits in the binary representation of a number. Syntax: int count() Parameter: The function accepts no parameter. Return Value: The function returns the number of set bits. It returns the total number of ones or the number of se 2 min read How to Create Stack of Bitset in C++? In C++, a stack is a container adapter that provides a last-in, first-out (LIFO) type of data structure with two major operations, namely push and pop while Bitset is a container that can store N bits and provides constant-time operations to manipulate individual bits. In this article, we will learn 2 min read std::bit_xor in C++ with Examples The bit_xor is an inbuilt function in C++ which is used to perform bitwise_xor and return the result after applying the bitwise_xor operation on it's arguments. Header File: #include <functional.h> Template Class: template <class T> struct bit_xor; Parameters: It accepts a parameter T wh 2 min read How to Count Set Bits in an Integer in C++? In binary representation of a number, a set bit is defined as the binary digit (bit) that is set to 1. In this article, we will learn how to count the set bits in a given integer in C++.ExampleInput: 13Output:The number of set bits in 13 (1101) is: 3Counting Set Bits in an IntegerTo count the set bi 2 min read Printing Boolean Values in C++ In C++, a boolean data type can only have two possible values true and false. However, when we print the boolean data types using the standard output streams like cout they are printed as 0 or 1 instead of true or false. In this article, we will learn how to print boolean values in C++ so that true 2 min read Like