note 109328 added to function.pack

From: Date: Fri, 06 Jul 2012 17:27:01 +0000
Subject: note 109328 added to function.pack
Groups: php.notes 
Request: Send a blank email to php-notes+get-189055@lists.php.net to get a copy of this message
Even though in a 64-bit architecure intval(6123456789) = 6123456789, and sprintf('%b', 5000000000) = 100101010000001011111001000000000 pack will not treat anything passed to it as 64-bit. If you want to pack a 64-bit integer: $big = 5000000000; $left = 0xffffffff00000000; $right = 0x00000000ffffffff; $l = ($big & $left) >>32; $r = $big & $right; $good = pack('NN', $l, $r); $urlsafe = str_replace(array('+','/'), array('-','_'), base64_encode($good)); //done! //rebuild: $unurl = str_replace(array('-','_'), array('+','/'), $urlsafe); $binary = base64_decode($unurl); $set = unpack('N2', $tmp); print_r($set); $original = $set[1] << 32 | $set[2]; echo $original, "\r\n"; results in: Array ( [1] => 1 [2] => 705032704 ) 5000000000 but ONLY on a 64-bit enabled machine and PHP distro. ---- Server IP: 69.147.83.197 Probable Submitter: 216.82.251.227 ---- Manual Page -- http://www.php.net/manual/en/function.pack.php Edit -- https://master.php.net/note/edit/109328 Del: integrated -- https://master.php.net/note/delete/109328/integrated Del: useless -- https://master.php.net/note/delete/109328/useless Del: bad code -- https://master.php.net/note/delete/109328/bad+code Del: spam -- https://master.php.net/note/delete/109328/spam Del: non-english -- https://master.php.net/note/delete/109328/non-english Del: in docs -- https://master.php.net/note/delete/109328/in+docs Del: other reasons-- https://master.php.net/note/delete/109328 Reject -- https://master.php.net/note/reject/109328 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#189055) next »