Interpreting as unsigned 32 bit integer with PHP -


i trying make little php tool world of tanks read battle replays. can see there each replay consists of , there example.

unfortunately don't understand part of wiki article:

read 4 bytes, , interpret these unsigned 32 bit integer, let "block count"

i tried convert java code php, outputs "0" time. tried code found @ php.net/manual/en/language.types.integer.php#38478 outputs "0" too.

here current code:

function parse($string) { $x = (float)$string; if ($x > (float)2147483647) $x -= (float)"4294967296"; return (int)$x; }  $replay = file_get_contents('steppes.txt');  $magic = substr($replay, 0, 4); $count = substr($replay, 4, 4);  echo $magic." -- ".parse($magic)."<br>".$count." -- ".parse($count); 

you can use php-function unpack convert binary data.

in case should use code v for

unsigned long (always 32 bit, little endian byte order)

(long name used 32bit integer). didn't specify used byte-order, looking @ demo-data assume little endian. list of 'codes', see documentation of pack-function.

$replay = file_get_contents('steppes.txt'); $info = unpack('vmagic/vcount', $replay); echo 'magic: ' . $info['magic']; echo '<br/>'; echo 'count: ' . $info['count']; 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -