Convert IEEE 754 to Decimal Point

I have what I think is IEEE754 with single or double precision (not sure) and I would like to convert it to decimal code in PHP.

Given a 4 hexadecimal value (which can be in a small terminal format, so basically the reverse order) 4A,5B,1B,05 I need to convert it to a decimal value, which, as I know, will be very close to 4724.50073 .

I tried some online converters, but they are far from the expected result, so I obviously missed something.

If I echo 0x4A; I get 74 , and the rest 91 , 27 and 5 . Not sure where to get it from here ...

+7
decimal php ieee-754 hex
source share
1 answer

To convert it to float, use unpack . If the byte order is incorrect, you will have to cancel it 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[1]; // 3589825.25 

I see no way how this compares to 4724.50073 directly tho. Without any additional test data or manufacturer guidance, this question does not fully answer.

Speculation: judging by the size of the coordinate, this is probably some kind of projection (XYZ or Mercator), which can then be converted to WGS84 or whatever you need. Unfortunately, there is no way to check, since you did not specify the latitude and longitude.

+1
source share

All Articles