Hey,
im looking for a way to get a double value to follow the IEEE 754 standard, iv seen a number of librarys for it on java but i had my doubts to whether it was a problem that wasnt solved already with a java standard library. The value i am expecting in hex is :

66 66 66 66 C6 4B 40 

or 55.55 in decimal.
However using a standard floating point number in java produces the following :

double f = 55.55;
System.out.print(Double.toHexString(f));
--output--------------------------------
0x1.bc66666666666p5

Which im pretty sure is either the wrong standard/order for the floating point number i wish to output to the file i am working with. So does anyone know how to set a floating point number to IEEE 754 standard is my question :)

Recommended Answers

All 2 Replies

Take a look at this. Basically, you'll want to use Double.toLongBits(f) or Double.toRawLongBits(f) (the difference between the two pertains to NaN values; see the documentation). These will give you a long integer, which you should be able to use Long.toHexString() to get the actual IEEE 754 value.

Worked a treat i think, thank you. Thumbs up

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.