title: Bit shifting `char` vs. `unsigned char`
body: <p>I need to convert 2 bytes in <code>char pcm[]</code> to a 1 byte <code>short pcm_[]</code>. <a href="https://stackoverflow.com/questions/16851340/cast-char-to-short">This</a> post used a C-style cast, which at first I tried out in my C++ program (using Qt):</p>
  
  <pre><code>#include &lt;QCoreApplication&gt;
  
  #include &lt;QDebug&gt;
  
  int main(int argc, char *argv[])
  {
      QCoreApplication a(argc, argv);
  
      char pcm[2] = {0xA1, 0x12};
      qDebug()&lt;&lt;pcm[0]&lt;&lt;pcm[1];
  
      short pcm_ = ( pcm[1] &lt;&lt; 8 )| pcm[0];
      qDebug()&lt;&lt;pcm_;
  
      short pcm_2 =  ((unsigned char)(pcm[1])) &lt;&lt; 8| (unsigned char) pcm[0];
      qDebug()&lt;&lt;pcm_2;
  
      return a.exec();
  }
  </code></pre>
  
  <p>I figured out that it only works if I use <code>unsigned char</code> in the bit shifting, but do not understand, why this is necessary as the input is a <code>char</code>. </p>
  
  <p>Moreover, I would like to use C++-style-cast, and came up with this one:</p>
  
  <pre><code>short pcm_3 = (static_cast&lt;unsigned char&gt;(pcm[1])) &lt;&lt; 8|
                 static_cast&lt;unsigned char&gt;(pcm[0]);
  qDebug()&lt;&lt;pcm_3;
  </code></pre>
  
  <p>Again, I need to use <code>unsigned char</code> instead of <code>char</code>. </p>
  
  <p>So I have 2 questions: </p>
  
  <ul>
  <li>Is <code>static_cast</code> the right cast? In my mind is an example from somewhere that used a <code>reinterpret_cast</code>. However, the reinterpret cast does not work.</li>
  <li>Why do I have to use <code>unsigned char</code>?</li>
  </ul>