title: Signed to unsigned conversion
body: <p>Can anyone explain why the following code outputs what it does:</p>
  
  <pre><code>char c = -1;
  cout &lt;&lt; (c &lt;&lt; 8) &lt;&lt; endl;
  cout &lt;&lt; ((unsigned char) c &lt;&lt; 8) &lt;&lt; endl;
  cout &lt;&lt; (c &lt;&lt; 24) &lt;&lt; endl;
  cout &lt;&lt; ((unsigned char) c &lt;&lt; 24) &lt;&lt; endl;
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>-256
  65280
  -16777216
  -16777216
  </code></pre>
  
  <p>I thought casting to an unsigned char would simply change the way the bits get interpreted. However, it's changed the results when shifting to the left by 8. What's strange is that this doesn't seem to be the case when shifting to the left by 24.</p>