How to convert 4 bytes array to float in java(如何在java中将4字节数组转换为浮点数)
问题描述
我有一个代表浮点值的 4 字节数组.从网络读取字节,例如 3e 3f e3 a0.如何将它从 byte[] 转换为 java 中的浮点数?
I have a 4 bytes array which represent a float value. The bytes is read from network, for example, 3e 3f e3 a0. How can I convert it from byte[] to float in java?
推荐答案
在 Java 中,char 是 16 位的.如果您的意思是您有 4 个小端字节顺序的 byte 值,您需要将其转换为 float 您可以使用 ByteBuffer.
In Java a char is 16-bit. If you mean you have a 4 byte values in little endian byte order which you need to convert to a float you can use ByteBuffer.
byte[] bytes = { }
float f = ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN).getFloat();
这篇关于如何在java中将4字节数组转换为浮点数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在java中将4字节数组转换为浮点数
基础教程推荐
- Struts2 URL 无法访问 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 存储 20 位数字的数据类型 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
