I have what I think it is an IEEE754 with single or double precision (not sure) and I’d like to convert it to decimal on PHP.
Given 4 hex value (which might be in little endian format, so basically reversed order)
4A,5B,1B,05 I need to convert it to a decimal value which I know will be very close to
I’ve tried some online converters but they are far from the expected result so I’m clearly missing something.
echo 0x4A; I get
74 and the others are
5. Not sure where to take it from here…
To convert it to float, use
unpack. If the byte order is incorrect, you’ll have to reverse it yourself before unpacking. 4 bytes (32 bits) usually means it’s a float, 8 for double.
$bin = "\x4A\x5B\x1B\x05"; $a = unpack('f', strrev($bin)); echo $a; // 3589825.25
I don’t see any way how this maps to
4724.50073 directly tho. Without any more test data or manufacturer’s manual this question is not fully answerable.
Speculation: judging from the size of the coordinate it’s probably some sort of projection (XYZ or mercator) which can then be converted to WGS84 or whatever you need. Unfortunately there’s no way to check since you haven’t provided both latitude and longitude.