将8字节的小尾数二进制转换为双精度浮点数 [英] Converting 8 bytes of little-endian binary into a double precision float

查看:597
本文介绍了将8字节的小尾数二进制转换为双精度浮点数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个二进制文件,我逐字节阅读。

我遇到一个8字节长的部分,持有双精度浮点数(小端) 。我无法弄清楚如何读取这些信息,并通过屏蔽和/或转换来正确计算。



(具体来说,文件类型是.LAS,但是那应该没关系)。

是否有任何Java技巧?

解决方案

您可以使用 ByteBuffer

byte [] bytes

  double d = ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN).getDouble(); 

来自一个套接字

  ByteBuffer bb = ByteBuffer.allocate(64 * 1024).order(ByteOrder.LITTLE_ENDIAN); 
socket.read(bb);
bb.flip();
double d = bb.getDouble();


I have a binary file that I read byte by byte.

I come across a section that is 8 bytes long, holding a double precision float (little endian). I can't figure out how to read this in and calculate it properly with masking and/or casting.

(To be specific, the file type is .LAS, but that shouldn't matter).

Are there any Java tricks?

解决方案

You can use ByteBuffer

from a byte[] bytes

 double d = ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN ).getDouble();

from a Socket

 ByteBuffer bb = ByteBuffer.allocate(64*1024).order(ByteOrder.LITTLE_ENDIAN );
 socket.read(bb);
 bb.flip();
 double d = bb.getDouble();

这篇关于将8字节的小尾数二进制转换为双精度浮点数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆