0

I've a float value represented in bits, stored in a 32-bit integer value. In Java , I can get float value by Float.intBitsToFloat

What's equivalent method in Objective-C?

I try to get the float by calling [[NSNumber numberWithInt:value] floatValue], its wrong

Qing Xu
  • 2,704
  • 2
  • 22
  • 21
  • Objective C is an extension of C, so you can use the same solution suggested [here](http://stackoverflow.com/questions/12342926/casting-float-to-int-bitwise-in-c). – Glorfindel Jun 18 '15 at 07:35

1 Answers1

0

According to JDK doc@http://docs.oracle.com/javase/7/docs/api/java/lang/Float.html#intBitsToFloat(int)

I write a C method:

float intBitsToFloat(int bits) {
    int s = ((bits >> 31) == 0) ? 1 : -1;
    int e = ((bits >> 23) & 0xff);
    int m = (e == 0) ?
    (bits & 0x7fffff) << 1 :
    (bits & 0x7fffff) | 0x800000;
    return s *m * pow(2,e -150);
}
Qing Xu
  • 2,704
  • 2
  • 22
  • 21