title: converting from a vector of char to a vector of short and a vector of float
body: <p>I have written this program to convert from a char to a short:</p>
  <pre><code>typedef unsigned char u8;
  typedef unsigned short u16;
  
  u16 combine2bytes(u8 a, u8 b) {
      return b | (a &lt;&lt; 8);
  }
  
  
  int main()
  {
      std::vector&lt;char&gt; cVec{ 'a','r','t','u' };
      std::vector&lt;short&gt;sVec;
      for (auto i = 0; i &lt; cVec.size(); i+=2)
      {
          sVec.push_back(combine2bytes(cVec.at(i),cVec.at(i+1)));
      }
      std::cout &lt;&lt; sVec.size() &lt;&lt; '\n';
      for (auto i = 0; i &lt; sVec.size(); i++)
          std::cout &lt;&lt; sVec.at(i) &lt;&lt; '\n';
      return 0;
  }
  </code></pre>
  <p>So if I understand, if we have a vector (or an array) of 1 byte data and I want to create a 2-byte vector from that 1-byte vector, I have to read 2 bytes from that 1-byte vector? Is this correct? same goes to float and int; we have to read 4 consecutive bytes?</p>
  <p>but if I have to read from file, suppose this is the file:</p>
  <pre><code>F0 5A 6B A9 4C E3 etc..
  </code></pre>
  <p>suppose now that I want to cast it to short, so I have to take: <code>F0 and 5A</code> but which one is the LSB and MSB (N.B.: the structure is little Endian)?</p>
  <p>And if I have to cast it to a float: how I can cast it so I can get floating point? because if I will cast it to a float, it's similar as I cast it to int? how to get the floating point?</p>
  <p>Thanks in advance</p>