Home/Support/Support Forum/Is there a way to convert from 64-bit hexadecimal representation to decimal floating-point with a rabbit 4000?
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

Is there a way to convert from 64-bit hexadecimal representation to decimal floating-point with a rabbit 4000?

0 votes
I´m reading this hex value 0x403988544C886ECF thru serial port with a Rabbit 4000 and I need to convert it to a floating point IEEE-754 representation. I have already done this with a 32-bits hexadecimal using the following function:

(example)
FRoll = *(float *)&RRoll; (where RRoll is the 32-bits hex)

Is there any similar function for the 64-bits representation?

Thanks in advance!
asked Sep 27, 2018 in Rabbit Software by MBusq55 New to the Community (2 points)

Please log in or register to answer this question.

1 Answer

0 votes
 
Best answer
I don't think you're going to find a simple solution to this problem. The Rabbit's "double" is 32 bits, just like its "float".

If it isn't possible for you to make the conversion on the remote end of the serial connection (for example, by casting the 64-bit double to a 32-bit float), you'll have to find existing code or write your own code to do the conversion.

If writing your own code, you'll need to identify special values and convert them accordingly, and then break up the bits of the 64-bit double into the exponent and mantissa, and scale them down to the sizes available in a 32-bit float.

And then write a lot of unit tests to make sure you're doing it correctly!

Here's some code to convert from single-precision (32-bits) to half-precision (16-bits) that could serve as a model for going from 64 to 32 bits: https://stackoverflow.com/a/3542975/266392

And there might be code in this library to do the conversion: http://www.jhauser.us/arithmetic/SoftFloat.html
answered Sep 27, 2018 by TomCollins Veteran of the Digi Community (1,368 points)
selected Oct 2, 2018 by MBusq55
...