title: How to iterate over subsets of a bitwise mask?
body: <p>I have a bitwise mask represented as an integer. The mask and integer is limited to 32-bit integers.</p>
  <p>I am interested in examining all subsets of the set bits of a given mask/integer, but I don't know of a good way to quickly find these subsets.</p>
  <p>The solution that I've been using is</p>
  <pre><code>for(int j = 1; j &lt;= mask; ++j)
  {
    if(j &amp; mask != 0)
    {
      // j is a valid subset of mask
    }
  }
  
  </code></pre>
  <p>But this requires looping from <code>j = 1</code> to <code>mask</code>, and I think there should be a faster solution than this.</p>
  <p>Is there a faster solution than this?</p>
  <p>My followup question is if I want to constrain the subset to be of a fixed size (i.e., a fixed number of set bits), is there a simple way to do that as well?</p>