title: Convert unsigned char to unsigned short (big endian)
body: <p>I have a LabVIEW program (not mine) which save data (uint16) in a binary file like this:
  <a href="https://i.stack.imgur.com/8vGsR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8vGsR.png" alt="enter image description here"></a></p>
  
  <ul>
  <li>Split the number by 2^8 to get 2 uint8 (for example 320 = 256 + 64)</li>
  <li>Switch the data before to save (so here begin with 64 and finish with 256)</li>
  </ul>
  
  <p>It is why I read 4 octets to get 2 unsigned short</p>
  
  <pre><code>ifstream is("filename", ifstream::binary);
  if (is) {
      is.seekg(0, is.end);
  
      unsigned char data_char[4];
      unsigned short data;
  
      is.seekg(376, is.beg);
      is.read(reinterpret_cast&lt;char*&gt;(width), sizeof(width));
  
      // What I tried (switch and convert)
      data = data_char[1]&lt;&lt;24 + data_char[0]&lt;&lt;16 + data_char[3]&lt;&lt;8 + data_char[2];
  }
  </code></pre>
  
  <p>For example the value 320 (uint8) is saved in the file and when I read data_char I have an unsigned char with the 4 composants of the number :</p>
  
  <ul>
  <li>[0] = 0 '\0'</li>
  <li>[1] = 64 '@'</li>
  <li>[2] = 1 '\x1'</li>
  <li>[3] = 0 '\0'</li>
  </ul>
  
  <p>And with 256 I have :</p>
  
  <ul>
  <li>[0] = 1 '\x1'</li>
  <li>[1] = 0 '\0'</li>
  <li>[2] = 0 '\0'</li>
  <li>[3] = 0 '\0'
  The [0] and [1] is the first uint8 and [2] and [3] the second.</li>
  </ul>
  
  <p>But, being a novice in C++, I tried a bit shift to convert the char to a short, but I am not doing the right way. </p>
  
  <p>I know for you it is something easy but an you help me please ?</p>
  
  <p>For information, in Python I just have to do: <code>sum(struct.unpack("&gt;HH", f.read(4))</code></p>