title: Integer to bitfield as a list
body: <p>I've created a method to convert an <code>int</code> to a bitfield (in a list) and it works, but I'm sure there is more elegant solution- I've just been staring at it for to long.</p>
  
  <p>I'm curious, how would you convert a <code>int</code> to a bitfield represented in a <code>list</code>?</p>
  
  <pre><code>def get(self):
      results = []
  
      results.append(1 if (self.bits &amp;   1) else 0)
      results.append(1 if (self.bits &amp;   2) else 0)
      results.append(1 if (self.bits &amp;   4) else 0)
      results.append(1 if (self.bits &amp;   8) else 0)
      results.append(1 if (self.bits &amp;  16) else 0)
      results.append(1 if (self.bits &amp;  32) else 0)
      results.append(1 if (self.bits &amp;  64) else 0)
      results.append(1 if (self.bits &amp; 128) else 0)
  
      return results
  
  def set(self, pin, direction):
      pin -= 1
      if pin not in range(0, 8): raise ValueError
  
      if direction: self.bits |= (2 ** pin)
      else: self.bits &amp;=~(2 ** pin)
  </code></pre>