I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com

Bit Vector

A bit_vector is more like a vector < bool >
+ View version details

Key Facts

Gyroscopic Couple: The rate of change of angular momentum (\inline \tau) = \inline I\omega\Omega (In the limit).
  • \inline I = Moment of Inertia.
  • \inline \omega = Angular velocity
  • \inline \Omega = Angular velocity of precession.


Bit_vector is defined in the standard header <vector>, and in the nonstandard backward-compatibility header <bvector.h>.


A bit_vector is like a vector<bool>. The difference between the two is that a vector requires at least one byte per element, but a bit_vector only requires one bit per element.

Short example of using bit_vector:

bit_vector V(5);
V[0] = true;
V[1] = false;
V[2] = false;
V[3] = true;
V[4] = false;
for (bit_vector::iterator i = V.begin(); i < V.end(); ++i)
  cout << (*i ? '1' : '0');
cout << endl;

If you need a container for a variable number of bits or Boolean values, you can use the class bit_vector, otherwise if you need a bitfield with static size, you should use bitset.

Bit_vector Operations

Operation Effect
c.flip() Negates all Boolean elements (complement of all bits)
m[i].flip() Negates the Boolean element with index i (complement of a single bit)
m[i]=val Assigns val to the Boolean element with index i (assignment to a single bit)
m[i1] = m[i2] Assigns the value of the element with index i2 to the element with index i1


Example - implicit casts to a variable of bit_vector
This example of program illustrates examples of implicit casts done by the ostream class to a variable of bit_vector.
#include <vector>
#include <iostream>
using namespace std;
int main( )
   bit_vector v; 
   bit_vector::reference ref1=v.at(0);
   cout <<ref1<<endl; // ref1 implicitly cast to bool 
   bool b1; 
   // one form of an explicit cast
   b1=ref1.operator bool( );
   cout <<b1<<endl; 
   // another form of an explicit cast
   cout <<b1<<endl;
   return 0;