我以位表示的浮点值,存储在32位整数值中。 在Java中,我可以通过Float.intBitsToFloat获得浮点值
Objective-C中的等效方法是什么?
我试着通过调用[[NSNumber numberWithInt:value] floatValue]得到浮点数,错误
答案 0 :(得分:0)
根据JDK doc @ http://docs.oracle.com/javase/7/docs/api/java/lang/Float.html#intBitsToFloat(int)
我写了一个C方法:
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);
}