2

I have a binary file that I'm trying to parse. A little part of the file has a set of coordinates (latitude and longitude). A small example could be as follow:

$data = "64DA7300 0CD5DFFF";

And I'm trying to see the integers but I have no luck yet.

$header = unpack("ilatitud/ilongitude", $data);
print_r($header);

I know the correct numbers should be: (7592548, -2108148), however the results are 1094988854, 808465207.

Any ideas? Thanks.

Peter Featherstone
  • 7,835
  • 4
  • 32
  • 64
user143
  • 25
  • 3
  • Is it ADS-B coordinates? If I remember correct they need more than just a normal hex -> binary conversion – Andreas Jul 18 '17 at 16:12
  • They are just GPS coordinates, the result needs to be divided by 65536 to get the exact coordinate. However, my problem is the conversion.. :/ – user143 Jul 18 '17 at 16:24
  • `$data = "64DA7300 0CD5DFFF";` thats not in binary. – tkausl Jul 18 '17 at 16:28
  • @tkausl Yes... Your point is? If you are refering to my comment on binary you could figure out how ADS-B GPS works. It's the stuff airplanes send out to ground telling them where they are. The stuff that makes flightradar work. Since full sized GPS signals was too large for airplanes they compressed it hex -> binary -> decimal to get the coordinates. – Andreas Jul 18 '17 at 16:33
  • My point is, you're trying to unpack a binary little-endian int from a string which contains the int as ascii-hex. – tkausl Jul 18 '17 at 17:31

1 Answers1

3
$data = "64DA7300 0CD5DFFF";

Your data is not in binary, it is hex-encoded ascii. Make it binary first:

$data = hex2bin(str_replace(" ", "", $data));

then your unpack will work.

Example

tkausl
  • 13,686
  • 2
  • 33
  • 50