title: How do I convert an int to bits?
body: <p>Long time <strong>READER</strong> of the site, first question I've had to ask as I can't find an answer on here; maybe I'm not using the right search terms or I'm just trying to do it in a completely obscure way =/</p>
  
  <p>I'm working with an Arduino and some LEDs forming a matrix board, and trying to get text/symbols to display on it. In order to achieve this I've mapped some digits (0 &amp; 1 to start with) and which pixels need to come on to form them (each will be 5 high, by 3 wide). I have been trying to store these in an array as follows:</p>
  
  <pre><code>int displayLetters[2][4] = { // [2] = number of chars/digits contained in array, [4] = display width (3) + 1 blank column 
    {11111,10001,11111,00000}, // 0
    {01001,11111,00001,00000} // 1
  };
  </code></pre>
  
  <p>I then created the following (what I thought would be a simple) function to "explode" those into an array of 0's and 1's as necessary which then gets iterated over to determine whether the LED should be on or off.</p>
  
  <pre><code>void convertToBits(int inputValue, int outputArray[]) {
    int i = 0;
  
    if (inputValue == 0) { // set all values of array to zero
      for (i = 0; i &lt; 5; i++) {
        outputArray[4-i] = 0;
      }
    } else {    
      while (inputValue &gt; 0) {
        int digit = inputValue % 10;
        outputArray[4-i] = digit; // 4-i to prevent digits being stored in reverse order
  
        inputValue /= 10;
        i++;
      }
    }
  }
  </code></pre>
  
  <p>Expecting that for <code>displayLetters[1][0]</code> I would get an array like {0,1,0,0,1}. But when it gets to <code>convertToBits</code> it's showing this as 513 (which I think is the HEX value?). </p>
  
  <p>If I put the values as just <code>1001</code>, <code>11111</code> (that one works fine already), <code>1</code> and <code>0</code> (also works fine) respectively, then it behaves as expected. I'd like to keep the leading zeroes if possible for readability, but if it can't be done like that, I guess I can lose them.</p>
  
  <p>I've played around with all sorts of data types, strings, uint8_t, unsigned int, etc and I can never get it to do what I need.</p>
  
  <p>Any assistance greatly appreciated, and I hope I've included enough information. I've omitted the rest of the code as I deem that to be stable and behaving as expected, the issues are being caused by the <code>convertToBits</code> function / data being passed to it.</p>
  
  <p>Many thanks!</p>