JAVA /如何将2字节浮点数转换为double值

时间:2017-02-09 12:23:55

标签: java

我正在尝试将0D 82的2字节浮点值转换为项目的双倍值。

当我模拟该值时,我得到28.2。 那么如何将这个2字节的浮点值转换为java的双倍值?

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

查看以下库:

https://sourceforge.net/p/calimero/wiki/Home/

它为KNX网络及其数据类型提供Java API。这很可能会做你想要的 - 特别是export function updateUser(req, res) { console.log(req.body) firstName = sanitizeHtml(req.body.user.firstName ); lastName = sanitizeHtml(req.body.user.lastName); studentId = sanitizeHtml(req.body.user.studentId); email = sanitizeHtml(req.body.user.email); password = sha512(req.body.user.password).toString('hex'); let update = { firstName, lastName, studentId, email, password }; User.findOneAndUpdate({_id: req.params.cuid}, {$set: updated}, function (err, user) {//correct structure if(error){ return res.status(500).send(err); }else{ return res.json({ user: updated }); } }); } 类。

您可以使用此代码:

tuwien.auto.calimero.dptxlator.DPTXlator2ByteFloat

byte[] test = new byte[2]; test[0] = (byte)0x0D; test[1] = (byte)0x82; DPTXlator2ByteFloat floatTranslator = new DPTXlator2ByteFloat(DPTXlator2ByteFloat.DPT_AIR_PRESSURE); floatTranslator.setData(test); double value = (double)floatTranslator.getValueFloat(); 变量将具有预期的28.2值。

在maven依赖项中导入以下内容以包含库:

value

希望这有帮助。