C++ Standard Library bitset Sample

Description

bitset is a container representing an array of N bits, where the value N is known at compile time. The array bits are indexed from 0 to N-1. A bitset is fixed in size, unlike a vector<bool>. A bitset provides the usual operations on bits, such as shifting and AND/OR/XOR.

Declaration

	template <size_t N>
	    class std::bitset;

Concept

The sample program establishes three bitsets, one initialized from a string, one from an unsigned long, and one defaulting to all zero bits. The rightmost bit of b3 is set, and then b1 and b2 are logically ANDed together, followed by a similar OR operation with b1 and b3. Finally, the bits are displayed, from highest (bit 7) to lowest (bit 0). The output is 00001011.

Special Notes:

A bitset is likely to be much more efficient than storing bits as char or int values.

Supported
Supported
Supported