title: How to convert four byte array to float in Objective C?
body: <p>I have four byte array and I like to convert to float in Objective C.
  I tried three approaches and not sure what is the right approach.</p>
  
  <p>What I tried are</p>
  
  <pre><code>        unsigned char *bytearray = (unsigned char *)calloc(4, sizeof(unsigned char));
          bytearray[0] = GolfResult[i]; bytearray[1] = GolfResult[i+1]; bytearray[2] = GolfResult[i+2]; bytearray[3] = GolfResult[i+3];
  
      Method 1
  
          float result = [[NSNumber numberWithUnsignedChar:*bytearray] floatValue];
  
      Method 2
  
          float result = (float)((bytearray[3] &lt;&lt; 24) | (bytearray[2] &lt;&lt; 16) | (bytearray[1] &lt;&lt; 8) | bytearray[0]);
  
      Method 3
          float result = (float)((bytearray[0] &lt;&lt; 24) | (bytearray[1] &lt;&lt; 16) | (bytearray[2] &lt;&lt; 8) | bytearray[3]);
  </code></pre>
  
  <p>What could be the correct method?</p>