/**
* 处理4个字节带小数的浮点数
* Created by wuhaowei(wuhaowei@dfsoft.com.cn)
* @DATE:2011-10-16 下午08:52:24
*
* @param b
* @return
*/
public static float byte2int_Float(byte b[]) {
int bits = b[3] & 0xff | (b[2] & 0xff) << 8 | (b[1] & 0xff) << 16
| (b[0] & 0xff) << 24;
int sign = ((bits & 0x80000000) == 0) ? 1 : -1;
int exponent = ((bits & 0x7f800000) >> 23);
int mantissa = (bits & 0x007fffff);
mantissa |= 0x00800000;
// Calculate the result:
float f = (float) (sign * mantissa * Math.pow(2, exponent - 150));
return f;
}
* 处理4个字节带小数的浮点数
* Created by wuhaowei(wuhaowei@dfsoft.com.cn)
* @DATE:2011-10-16 下午08:52:24
*
* @param b
* @return
*/
public static float byte2int_Float(byte b[]) {
int bits = b[3] & 0xff | (b[2] & 0xff) << 8 | (b[1] & 0xff) << 16
| (b[0] & 0xff) << 24;
int sign = ((bits & 0x80000000) == 0) ? 1 : -1;
int exponent = ((bits & 0x7f800000) >> 23);
int mantissa = (bits & 0x007fffff);
mantissa |= 0x00800000;
// Calculate the result:
float f = (float) (sign * mantissa * Math.pow(2, exponent - 150));
return f;
}
本文介绍了一种将4个字节的二进制数据转换为浮点数的方法。该方法通过位操作获取符号、指数及尾数部分,并利用这些信息计算出最终的浮点数值。
7170

被折叠的 条评论
为什么被折叠?



