title: C++: dynamic_bitset
body: <p>I'm having trouble initializing my <code>dynamic_bitset</code>. I have this code:  </p>
  
  <pre><code>for(int j=(data1.length()-1); j&gt;=0; j--){  
      x[j] = data1[j];  
  }
  </code></pre>
  
  <p>Where <code>data1</code> is a 32-bit binary number being read in from a file.</p>
  
  <p>When I output the values for <code>data1[j]</code>, it outputs the correct values I need to assign to x, but when I output x (after the supposed initialization), x is all ones. </p>
  
  <p>What am I doing wrong?  </p>
  
  <p>EDIT: I'm trying to decompress code. The compressed code is given in lines that are 32 bits long. I want to put everything into one structure for easy access.  </p>
  
  <p>My code to initialize x:  </p>
  
  <pre><code>int size = numLines * 32; //numLines is the number of lines of 32 bits
  boost::dynamic_bitset&lt;&gt; x(size);  
  </code></pre>
  
  <p>EDIT2:<br>
  There are 8 lines of 32-bits each. The <code>for</code> loop is nested within a <code>while</code> loop that accesses each of those 8 lines of 32-bit binary and assignes that value to data1, so data1 changes with every iteration of the <code>while</code> loop.<br>
  First iteration:</p>
  
  <pre><code>data1: 10001001110000001001011100110011  
  </code></pre>
  
  <p>Second iteration:</p>
  
  <pre><code>data1: 00110011001110001010001110000000  
  </code></pre>
  
  <p>Third iteration: </p>
  
  <pre><code>data1: 00000011100000000000000000000000 
  </code></pre>
  
  <p>etc....</p>
  
  <p>I want <code>x</code> to be a long bitset containing all those values concatenated with each other.  </p>
  
  <p>EDIT3:<br>
  Trying one method:    </p>
  
  <pre><code>for(int i=0; i&lt;numLines; i++){
      d.append(data1);
  }
  boost::dynamic_bitset&lt;&gt; x(std::string(d));
  </code></pre>