title: How to express an integer as the sum of powers-of-two?
body: <p>I have this number:</p>
  
  <pre><code>0101
  </code></pre>
  
  <p>and I know it is the binary sum of </p>
  
  <pre><code>0100
  0001
  </code></pre>
  
  <p>How can I get those values from the first one?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I have create a snippet of code based on the logic by JoeCortopassi. The snippet its this:</p>
  
  <pre><code>protected function _getSitesPublished($value) {
      static $bits = null;
      if (!$bits) {
          $bits = array ();
          $bit = 0;
          $x = 0;
          while ($bit &lt; 4294967295) {
              $bit = pow (2, $x);
              $bits [$bit] = $bit;
                              ++ $x;
          }
      }
      $sites = array ();
      foreach ($bits as $bit) {
          if (($value &amp; $bit) == $bit) {
              $sites [] = $bit;
          }
      }
      return $sites;
  }
  </code></pre>
  
  <p>It only create the bits the first time the method its called. I have to make the comprobation </p>
  
  <pre><code>if (($value &amp; $bit) == $bit)
  </code></pre>
  
  <p>since <code>$value &amp; $bit</code> will return an int (may be other than 0, as in <code>6 &amp; 3</code>) and because of that I can't use only <code>if ($value &amp; $bit)</code> </p>
  
  <p>Thanks to all for your help.</p>
  
  <p><strong>EDIT 2</strong>
  Oops! I had a little bug... forgot to increase the $x XD</p>