5
I am developing an application that receives data from a GPS board, the data is received by bluetooth in hexadecimal, the latitude and longitude values are floating points of 64 bits, which follows the standard IEEE 754.
I can already capture the hexadecimal values I need for a String variable. For example:
b3baf6e3530b38c0 (latitude)
ff198e4d752f4ac0 (longitude)
But I’m not able to transform this string with the hexadecimal value in the latitude and longitude values, for example: -24.123456789 and -52.123456789.
Does anyone know any way to interpret the hexadecimal value of a floating point, for a double variable?
Just to confirm, for the two values of your example the desired doubles would be respectively
-1.677999117094125E-59
and-1.7525333784680737E304
?– Anthony Accioly
@Anthonyaccioly I don’t know where Romão got these hexadecimal numbers from, but the two decimal numbers you suggested must be wrong, judging by their exponents.
– Victor Stafusa
Yeah, I even checked against a calculator. Maybe the bits are inverted somehow? :)
– Anthony Accioly
@Anthonyaccioly Yes, I’m also trying to do some mathematical tests to see if this can somehow produce a feasible number. The fact that they both end up with
c0
makes me suspect about some reordering.– Victor Stafusa
@Anthonyaccioly The IEEE 754 standard defines the returned hexa, as I saw in: https://pt.wikipedia.org/wiki/IEEE_754, hexa is composed of: Signal, exponent and mantissa.
– David Araujo
So I apologize, but I found the answer to why I can’t convert. I’m getting the mirrored values, so if I reverse the hexadecimal sequence and try to convert normally it returns the correct values. b3baf6e3530b38c0 is actually c0380b53e3f6bab3
– Romão Felipe