java - Python 解析 Java Double.toHexString(double) 的输出

标签 java python

是否可以在 Python 中解析从 Java Double.toHexString 方法编写的字符串?

http://docs.oracle.com/javase/7/docs/api/java/lang/Double.html#toHexString(double)

输出如下所示:“0x1.16d6b97e718ffp8” ...不确定这是否是标准化格式。

我期望类似的东西

value=float('0x1.16d6b97e718ffp8')

最佳答案

那就是float.fromhex :

>>> float.fromhex('0x1.16d6b97e718ffp8')
278.8387679126026

来自文档:

This syntax is similar to the syntax specified in section 6.4.4.2 of the C99 standard, and also to the syntax used in Java 1.5 onwards. In particular, the output of float.hex() is usable as a hexadecimal floating-point literal in C or Java code, and hexadecimal strings produced by C’s %a format character or Java’s Double.toHexString are accepted by float.fromhex().

关于java - Python 解析 Java Double.toHexString(double) 的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21768587/

相关文章:

java - Android在ant编译中包含.jar

Python尾随L问题

python - 如何添加到每行末尾附近的数字

python - 在开始和停止标志之间读取多个文件 block

python - 当我尝试将值迭代算法与 mdptoolbox 一起使用时出现 OverflowError

java - Maven 运行/调试配置 : what to put to command line to get Hello world to run

java - 使用 JavaFileManager 编译项目

java - 评估 Spring 的 context.xml 中的属性(基本模板)

java - 逆向工程 Java *.class 文件以更改变量的数据类型

python - 在 blender 脚本中将图像导入为平面