Learning to program has no more to do with designing interactive software than learning to touch type has to do with writing poetry Ted Nelson


Language C++ | Level Intermediate | Category Standard Template Library (STL) | 2015-11-16 22:01:21



The bit set is a container for storing the data at the bit level.


Bit 0 is the least significant bit and bit N-1 is the most significant bit.
Provides serialize / de-serialize with ostream and fstream.
The size of a bit set is determined at compile time.
Conversion mechanism to and from a textual representation.
A bit is set if its value is 1 and reset if its value is 0.

source Code

#include "stdafx.h"

#include < bitset >
#include < iostream >

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
	bitset<6> bit1(string("011101"));
	bitset<6> bit2(string("001111"));

	bitset<6> bitres = bit1 | bit2;
	bitset<6> bitresand = bit1 & bit2;

	cout << "Bitset one " << bit1 << endl;
	cout << "Bitset two " << bit2 << endl;
	cout << "OR with two bitset: " << bitres << endl;
	cout << "AND with two bitset: " << bitresand << endl;

	return 0;



					Bitset one 011101
					Bitset two 001111
					OR with two bitset: 011111
					AND with two bitset: 001101

When to use

When you need to store space efficient, you can use bit set.


Please login to add comments.