c++ Algorithm to convert an integer into an array of bool
<p>I'm trying to code an algorithm that will save to file as binary strings every integer in a range. Eg, for the range 0 to 7:</p>

<pre><code>0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
</code></pre>

<p>Note that the leading zeros and spaces between digits are essential. </p>

<p>What I cant figure out how to do in a simple way is to convert the integers to binary numbers represented by <code>bool []</code>s (or some alternate approach).</p>

<p><strong>EDIT</strong></p>

<p>As requested, my solution so far is:</p>

<pre><code>const int NUM_INPUTS = 6;
bool digits[NUM_INPUTS] = {0};
int NUM_PATTERNS = pow(2, NUM_INPUTS);

for(int q = 0; q &lt; NUM_PATTERNS; q++)
{
    for(int w = NUM_INPUTS -1 ; w &gt; -1 ; w--)
    {

        if( ! ((q+1) % ( (int) pow(2, w)))  )
            digits[w] = !digits[w];

        outf &lt;&lt; digits[w] &lt;&lt; " ";
    }

    outf &lt;&lt; "\n";
}
</code></pre>

<p>Unfortunately, this is a bit screwy as the first pattern it gives me is 000001 instead of 000000.</p>

<p>This is not homework. I'm just coding a simple algorithm to give me an input file for training a neural network.</p>
