title: How to access range of bits in a bitset?
body: <p>I have a bitset which is very large, say, 10 billion bits. </p>
  
  <p>What I'd like to do is write this to a file. However using <code>.to_string()</code> actually freezes my computer. </p>
  
  <p>What I'd like to do is iterate over the bits and take 64 bits at a time, turn it into a <code>uint64</code> and then write it to a file.</p>
  
  <p>However I'm not aware how to access different ranges of the bitset. How would I do that? I am new to c++ and wasn't sure how to access the underlying bitset::reference so please provide an example for an answer.</p>
  
  <p>I tried using a pointer but did not get what I expected. Here's an example of what I'm trying so far.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;bitset&gt;
  #include &lt;cstring&gt;
  using namespace std;
  
  int main()
  {
      bitset&lt;50&gt; bit_array(302332342342342323);
      cout&lt;&lt;bit_array &lt;&lt; "\n";
      bitset&lt;50&gt;* p;
      p = &amp;bit_array;
      p++;
      int some_int;
      memcpy(&amp;some_int, p , 2);
      cout &lt;&lt; &amp;bit_array &lt;&lt; "\n";
      cout &lt;&lt; &amp;p &lt;&lt; "\n";
      cout &lt;&lt; some_int &lt;&lt; "\n";
  
      return 0;
  }
  </code></pre>
  
  <p>the output</p>
  
  <pre><code>10000110011010100111011101011011010101011010110011
  0x7ffe8aa2b090                                                                                                                          
  0x7ffe8aa2b098
  17736
  </code></pre>
  
  <p>The last number seems to change on each run which is not what I expect.</p>