title: C reverse bits in unsigned integer
body: <p>I'm converting an unsigned integer to binary using bitwise operators, and currently do integer &amp; 1 to check if bit is 1 or 0 and output, then right shift by 1 to divide by 2. However the bits are returned in the wrong order (reverse), so I thought to reverse the bits order in the integer before beginning. </p>
  
  <p>Is there a simple way to do this?</p>
  
  <p>Example:
  So if I'm given the unsigned int 10 = 1010</p>
  
  <pre><code>while (x not eq 0) 
    if (x &amp; 1)
      output a '1'
    else 
      output a '0'
    right shift x by 1
  </code></pre>
  
  <p>this returns 0101 which is incorrect... so I was thinking to reverse the order of the bits originally before running the loop, but I'm unsure how to do this?</p>