note 112569 added to function.sprintf

From: Date: Sun, 30 Jun 2013 17:51:31 +0000
Subject: note 112569 added to function.sprintf
Groups: php.notes 
Request: Send a blank email to php-notes+get-195410@lists.php.net to get a copy of this message
To convert / use / implement 64-bit signed 2's complement Long type values in PHP code, use the following code // requires bcmath /* java 64-bit long: The long data type is a 64-bit signed two's complement integer. It has a minimum value of -9,223,372,036,854,775,808 and a maximum value of 9,223,372,036,854,775,807 (inclusive). Use this data type when you need a range of values wider than those provided by int. */ bcscale(0); $num = substr($data,0,8) // 8 binary bytes from file $long = bcadd(bcmul(unpack('N',substr($num,0,4))[1],bcpow(2,32)),unpack('N',substr($num,4,4))[1]); if(unpack('N',substr($num,4,4))[1] & 0x80000000) $long = bcadd($long,pow(2,32)); var_dump($long); // now you can use $long as 64-bit signed long value by using bcmath functions // do not use php math funcs, they cant handle 64-bit long integer values // use bcadd bcsub etc from bcmath functions freely Hope this helps people handling 64-bit long values retrieved from other languages like java, etc ---- Server IP: 69.147.83.199 Probable Submitter: 122.173.134.59 ---- Manual Page -- http://php.net/manual/en/function.sprintf.php Edit -- https://master.php.net/note/edit/112569 Del: integrated -- https://master.php.net/note/delete/112569/integrated Del: useless -- https://master.php.net/note/delete/112569/useless Del: bad code -- https://master.php.net/note/delete/112569/bad+code Del: spam -- https://master.php.net/note/delete/112569/spam Del: non-english -- https://master.php.net/note/delete/112569/non-english Del: in docs -- https://master.php.net/note/delete/112569/in+docs Del: other reasons-- https://master.php.net/note/delete/112569 Reject -- https://master.php.net/note/reject/112569 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#195410) next »