title: C++: convert unsigned long long to unsigned long
body: <p>I am trying to convert an unsigned long long to unsigned long. Is the following a correct way to do it?</p>
  
  <pre><code>unsigned long removeExtraBits2(unsigned long long c) {
      return (unsigned long) ((c &lt;&lt; 32) &gt;&gt; 32);
  }
  </code></pre>
  
  <p>If not, can you provide a working example?</p>
  
  <p>My assumption is that when shifting left, and then back right, the 32 leftmost bits get set to 0.</p>
  
  <p>Thanks!</p>
  
  <p>EDIT: The purpose of the conversion is to get rid of the extra bits, 'higher' than the 32nd, effectively keeping only the rightmost 32 bits into an unsigned long.</p>