title: Drawing XBM bitmaps on Arduino
body: <p>I am trying to parse an XBM bitmap on Arduino, with no luck at all (expect &lt;16x16 bitmaps). After much searching, researching and tinkering I have come up to this function. I'm sure I'm reading the bytes correctly (tested), there is something wrong with the conversion though.</p>
  
  <pre><code>void bitmap(int x, int y, uint16_t *bitmap, uint8_t w, uint8_t h) {
    uint16_t dots, msb;
    uint16_t col, row;
  
    msb = 1 &lt;&lt; (w - 1);
    for (row = 0; row &lt; h; row++) {
      dots = pgm_read_word(bitmap + row);
      //Serial.print(dots, HEX);
      //Serial.println(" ");
      for (col = 0; col &lt; w; col++) {
        if (dots &amp; (msb &gt;&gt; col))
          Serial.print("#"); //toolbox.setPixel(x, y, 1, false);
        else
          Serial.print("'"); //toolbox.setPixel(x, y, 0, false);
      }
      Serial.println("");
    }
  }
  </code></pre>
  
  <p>This is the bitmap I'm trying to show. It has a size of 32x32 pixels. Images of 16x16 or less are displayed correctly.</p>
  
  <pre><code>// 32x32
  uint16_t medium[] PROGMEM = {
    0xffff, 0xffff, 0x0000, 0x8000, 0xffff, 0xffff, 0x0001, 0x0000, 0xffff,
    0xffff, 0x0000, 0x8000, 0xffff, 0xffff, 0x0001, 0x0000, 0xffff, 0xffff,
    0x0000, 0x8000, 0xffff, 0xffff, 0x0001, 0x0000, 0xffff, 0xffff, 0x0000,
    0x8000, 0xffff, 0xffff, 0x0001, 0x0000, 0xffff, 0xffff, 0x0000, 0x8000,
    0xffff, 0xffff, 0x0001, 0x0000, 0xffff, 0xffff, 0x0000, 0x8000, 0xffff,
    0xffff, 0x0001, 0x0000, 0xffff, 0xffff, 0x0000, 0x8000, 0xffff, 0xffff,
    0x0001, 0x0000, 0xffff, 0xffff, 0x0000, 0x8000, 0xffff, 0xffff, 0x0001,
    0x0000 };
  </code></pre>
  
  <p>This is a PNG of the bitmap for reference: <img src="https://i.stack.imgur.com/ioine.png" alt=""></p>