java解析modbus协议64位双进度浮点数
package com.energy.business.socket.handler;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.DecimalFormat;
/**
* 64位浮点数 modbus协议数据解析
*/
public class Float64Utils {
public static String getDoubleByHexstr(String s) {
Long l = Long.valueOf(s,16).longValue();
double v = Double.longBitsToDouble(l);
BigDecimal bigDecimal = new BigDecimal(v);
return bigDecimal.toPlainString();
}
public static void main(String[] args) throws IOException {
//modbus协议报文
String data = "03030840AE580000000000c1af";
//协议报文格式为AB CD EF GH所以不需要到低位互换
System.out.println("解析双精度浮点数的值为:"+getDoubleByHexstr("40AE580000000000"));
}
}