title: How would I implement a bit map?
body: <p>I wish to implement a 2d bit map class in Python. The class would have the following requirements:</p>
  
  <ol>
  <li><p>Allow the creating of arbitrarily sized 2d bitmaps. i.e. to create an 8 x 8 bitmap (8 bytes), something like:</p>
  
  <pre><code>bitmap = Bitmap(8,8)
  </code></pre></li>
  <li><p>provide an API to access the bits in this 2d map as boolean or even integer values, i.e.:</p>
  
  <pre><code>if bitmap[1, 2] or bitmap.get(0, 1)
  </code></pre></li>
  <li><p>Able to retrieve the data as packed Binary data. Essentially it would be each row of the bit map concatenated and returned as Binary data. It may be padded to the nearest byte or something similar.</p>
  
  <pre><code>bitmap.data()
  </code></pre></li>
  <li><p>Be able to create new maps from the binary data retrieved:</p>
  
  <pre><code>new_bitmap = Bitmap(8, 8, bitmap.data())
  </code></pre></li>
  </ol>
  
  <p>I know Python is able to perform binary operations, but I'd like some suggestions as how best to use them to implement this class.</p>