note 92157 added to function.sprintf
| From: | jfgrissom at gmail dot com | Date: | Sun, 12 Jul 2009 04:51:49 +0000 |
| Subject: | note 92157 added to function.sprintf | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-158191@lists.php.net to get a copy of this message | ||
I had a nightmare trying to find the two's complement of a 32 bit number.
I got this from http://www.webmasterworld.com/forum88/13334.htm
(credit where credit is due... =P )
Quote: ...find out the 2's complement of any number, which is -(pow(2, n) - N) where n is the
number of bits and N is the number for which to find out its 2's complement.
This worked magic for me... previously I was trying to use
sprintf ("%b",$32BitDecimal);
But it always returned 10000000000000000000000 when the $32BitDecimal value got above 2,000,000,000.
This -(pow(2, n) - N)
Worked remarkably well and was very accurate.
Hope this helps someone fighting with two's complement in PHP.
----
Server IP: 64.71.164.2
Probable Submitter: 99.50.206.103
----
Manual Page -- http://www.php.net/manual/en/function.sprintf.php
Edit -- https://master.php.net/note/edit/92157
Del: integrated -- https://master.php.net/note/delete/92157/integrated
Del: useless -- https://master.php.net/note/delete/92157/useless
Del: bad code -- https://master.php.net/note/delete/92157/bad+code
Del: spam -- https://master.php.net/note/delete/92157/spam
Del: non-english -- https://master.php.net/note/delete/92157/non-english
Del: in docs -- https://master.php.net/note/delete/92157/in+docs
Del: other reasons-- https://master.php.net/note/delete/92157
Reject -- https://master.php.net/note/reject/92157
Search -- https://master.php.net/manage/user-notes.php