0

is there a possibility to parse in Python a string that was written from a Java Double.toHexString method?

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

The output looks like this: '0x1.16d6b97e718ffp8' ... not sure, whether this is a standardized format.

I would expect something like

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

1 Answer 1

2

That'd be float.fromhex:

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

From the docs:

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().

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.