Bitset Constructors [C++ Reference]
Keywords: stl,bitset,bitset_constructors
Date: 2008-10-14T15:42:06-0700

[[Bitset Constructors]]
C++ Reference
Translations of this page?:

- en
- br-pt
- cn
- fr
- it
- jp
- pl
- ru
- tr

## Bitset Constructors

Syntax:

        #include <bitset>
        bitset();
        bitset( unsigned long val );

Bitsets can either be constructed with no arguments or with an unsigned long number val that will be converted into binary and inserted into the bitset.

When creating bitsets, the number given in the place of the template determines how long the bitset is.

For example, the following code creates two bitsets and displays them:

     // create a bitset that is 8 bits long
     bitset<8> bs;
     // display that bitset
     for( int i = (int) bs.size()-1; i >= 0; i-- ) {
       cout << bs[i] << " ";
     }
     cout << endl;
     // create a bitset out of a number
     bitset<8> bs2( (long) 131 );
     // display that bitset, too
     for( int i = (int) bs2.size()-1; i >= 0; i-- ) {
       cout << bs2[i] << " ";
     }
     cout << endl;

Edit this page • Old revisions
• • • Login • Index • Recent changes • RSS • cc •