title: Power set generated by bits
body: <p>I have this code which generates power set of an array of size 4 (number is just example, less combinations to write...).</p>
  
  <pre><code>#define ARRAY_SIZE 4
  
  
  unsigned int i, j, bits, i_max = 1U &lt;&lt; ARRAY_SIZE;
  int array[ARRAY_SIZE];
  
  for (i = 0; i &lt; i_max ; ++i) {
      for (bits = i, j = 0; bits; bits &gt;&gt;= 1, ++j) {
          if (bits &amp; 1)
              printf("%d", array[j]);
      }
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>{}
  {1}
  {2}
  {1, 2}
  {3}
  {1, 3}
  {2, 3}
  {1, 2, 3}
  {4}
  {1, 4}
  {2, 4}
  {1, 2, 4}
  {3, 4}
  {1, 3, 4}
  {2, 3, 4}
  {1, 2, 3, 4}
  </code></pre>
  
  <p>I need that output to be like this one:</p>
  
  <pre><code>{1}
  {2}
  {3}
  {4}
  {1, 2}
  {1, 3}
  {1, 4}
  {2, 3}
  {2, 4}
  {3, 4}
  {1, 2, 3}
  {1, 2, 4}
  {1, 3, 4}
  {2, 3, 4}
  {1, 2, 3, 4}
  </code></pre>
  
  <p>So it has to be ordered like that. I can't do that ordering after that algorithm ends, I have to use every combination in every iteration, so It has to generate that combinations already ordered. Can someone help me out? I think I was thinking about everything...</p>
  
  <p>EDIT: That final output should be without empty set, but it's not priority.</p>