Java把1B 02 04 80 FF 82 A7 00 EF FE FE 7F 43 FF 38 FF 5B 01 AA 02 FF 7F 0A 01 FE 7F FE 7F FE 7F FE 7F 34 00 FE 7F FE 7F FE 7F 89 01 32 00 5C 00 5F 00 58 00 FE 7F FE 7F 1E 00 64 00 9E 01 86 BA 03 00 DE 1E 00 00 F0 4D 0F 00 FE 7F FE 7F EF FE 43 FF F5 0C 00 00 D3 01 1C 01 FE 7F FF 7F B9 D6 1B 04 FF FF截取部分字段转化成-18.9
时间: 2023-08-22 18:10:16 浏览: 60
用Java将字符串的首字母转换大小写
可以使用 Java 中的 ByteBuffer 类来进行字节序列的转换操作。具体步骤如下:
1. 把要转换的字节序列存储到一个 byte 数组中
```java
byte[] bytes = {0x1B, 0x02, 0x04, (byte)0x80, (byte)0xFF, (byte)0x82, (byte)0xA7, 0x00, (byte)0xEF, (byte)0xFE, (byte)0xFE, 0x7F, 0x43, (byte)0xFF, 0x38, (byte)0xFF, 0x5B, 0x01, (byte)0xAA, 0x02, (byte)0xFF, 0x7F, 0x0A, 0x01, (byte)0xFE, 0x7F, (byte)0xFE, 0x7F, (byte)0xFE, 0x7F, (byte)0xFE, 0x7F, 0x34, 0x00, (byte)0xFE, 0x7F, (byte)0xFE, 0x7F, (byte)0xFE, 0x7F, (byte)0x89, 0x01, 0x32, 0x00, 0x5C, 0x00, 0x5F, 0x00, 0x58, 0x00, (byte)0xFE, 0x7F, (byte)0xFE, 0x7F, 0x1E, 0x00, 0x64, 0x00, (byte)0x9E, 0x01, (byte)0x86, (byte)0xBA, 0x03, 0x00, (byte)0xDE, 0x1E, 0x00, 0x00, (byte)0xF0, 0x4D, 0x0F, 0x00, (byte)0xFE, 0x7F, (byte)0xFE, 0x7F, (byte)0xEF, (byte)0xFE, 0x43, (byte)0xFF, (byte)0xF5, 0x0C, 0x00, 0x00, (byte)0xD3, 0x01, 0x1C, 0x01, (byte)0xFE, 0x7F, (byte)0xFF, 0x7F, (byte)0xB9, (byte)0xD6, 0x1B, 0x04, (byte)0xFF, (byte)0xFF};
```
2. 创建 ByteBuffer 对象,设置字节序为 Little-endian
```java
ByteBuffer buffer = ByteBuffer.wrap(bytes);
buffer.order(ByteOrder.LITTLE_ENDIAN);
```
3. 使用 getShort() 方法获取下一个 short 类型的数据,并除以 10 得到转换后的结果
```java
short value = buffer.getShort();
float result = value / 10.0f;
```
4. 重复第3步,直到获取到所有要转换的数据,最后得到的结果即为 -18.9
```java
while (buffer.hasRemaining()) {
short value = buffer.getShort();
float result = value / 10.0f;
System.out.println(result);
}
```
阅读全文