title: Rotate right using bit operation in c
body: <p>I am trying to come up with a function <code>int rotateRight (int x, int n)</code> that rotates <code>x</code> to the right by <code>n</code>. For example,</p>
  
  <pre><code>rotateRight(0x87654321,4) = 0x76543218
  </code></pre>
  
  <p>This is what I have so far:</p>
  
  <pre><code>int rotateRight(int x, int n) {
    int mask = (((1 &lt;&lt; n)-1)&lt;&lt;(32-n));
    int reserve = (int)((unsigned) (x&amp;mask) &gt;&gt;(32-n));
    return (x &lt;&lt; n) | reserve; 
  }
  </code></pre>
  
  <p>However, I am forbidden to use any casting, and the allowed operations are <code>~</code> <code>&amp;</code> <code>^</code> <code>|</code> <code>+</code> <code>&lt;&lt;</code> and <code>&gt;&gt;</code>. Can anyone help me fix this?</p>