title: Converting floats to NSData and back in Objective-C
body: <p>In an iphone application, I'm looking to convert a float to NSData for it to be sent over bluetooth and then converted back again when it's received. I have the bluetooth part working fine, but when I use this to convert to NSData:</p>
  
  <pre><code>NSData *data = [[NSData alloc]init];
  
  float z = 9.8574; // Get the float value, 9.8574 is just an example
  
  [data getBytes:&amp;z length:sizeof(float)];
  </code></pre>
  
  <p>I can not convert it back to a float. I've tried a couple of methods but I'm wondering if this is the correct way to encode the float to NSData??</p>
  
  <p>Thanks</p>