user143
user143

Reputation: 35

Unpack signed int32 little-endian in PHP

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.

Upvotes: 3

Views: 868

Answers (1)

tkausl
tkausl

Reputation: 14279

$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

Upvotes: 4

Related Questions