title: Converting int to bytes and switching endian efficiently
body: <p>I have to do some int -> byte conversion and switch to big endian for some MIDI data I'm writing.  Right now, I'm doing it like:</p>
  
  <pre><code>int tempo = 500000;
  char* a = (char*)&amp;tempo;
  
  //reverse it
  inverse(a, 3);
  
  [myMutableData appendBytes:a length:3];
  </code></pre>
  
  <p>and the inverse function:</p>
  
  <pre><code>void inverse(char inver_a[],int j)
  {
      int i,temp;
      j--;
      for(i=0;i&lt;(j/2);i++)
      {
        temp=inver_a[i];
        inver_a[i]=inver_a[j];
        inver_a[j]=temp;
         j--;
       }
  }
  </code></pre>
  
  <p>It works, but it's not real clean, and I don't like that I'm having to specify <code>3</code> both times (since I have the luxury of knowing how many bytes it will end up).</p>
  
  <p>Is there a more convenient way I should be approaching this?</p>