title: Converting InputStream data to different datatypes
body: <p>I have been working with InputStreams in Objective-C and seem to have taken the wrong step into the processing of the received data. </p>
  
  <p>I am receiving chunks of bytes, which are read and converted to datatypes, as integers, floats, doubles etc.</p>
  
  <p>So far my process is like this:</p>
  
  <pre><code>readBuffer = (uint8_t *) malloc(4);
  memset(readBuffer, 0, 4);
  while (length &lt; byteLength) {
      length = [InputStream read:readBuffer 4];
  }
  [something fourByteUint8ToLong:readBuffer];
  </code></pre>
  
  <p>Now in order to do some converting from the 4-bytes to long</p>
  
  <pre><code>- (long) fourByteUint8ToLong:(uint8_t *) buffer
  {
      long temp = 0;
      temp |= buffer[0] &amp; 0xFF;
      temp &lt;&lt;= 8;
      temp |= buffer[1] &amp; 0xFF;
      temp &lt;&lt;= 8;
      temp |= buffer[2] &amp; 0xFF;
      temp &lt;&lt;= 8;
      temp |= buffer[3] &amp; 0xFF;
      return temp;
  }
  </code></pre>
  
  <p>Is there not an easier way to handle this by using the objective-C classes?</p>
  
  <p>In that case how? 8-bytes -> double, 4-bytes -> float.</p>
  
  <p>Thanks in advance.</p>