Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) std::bitset

 

std::bitset is a container for bits.

 

#include <bitset>
#include <iostream>

int main()
{
  const int sz = 8;
  std::bitset<sz> x;
  for (int i=0; i!=sz; ++i)
  {
    std::cout << x << '\t' << x.to_ulong() << '\n';
    x[i] = true;
  }
  std::cout << x << '\t' << x.to_ulong() << '\n';
}

 

Screen output:

 

00000000 0
00000001 1
00000011 3
00000111 7
00001111 15
00011111 31
00111111 63
01111111 127
11111111 255

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict