Re: Can this code go faster?
| From: | Jason Barnett | Date: | Tue, 26 Apr 2005 17:26:10 +0000 |
| Subject: | Re: Can this code go faster? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-213946@lists.php.net to get a copy of this message | ||
René Fournier wrote:
I've looked in the docs and don't see anything for this per se...
I need to convert a binary number of arbitrary length to a signed integer.
This is how I'm doing it now:
CODE
--------
function bin2int ($bin) {
if (substr($bin,0,1) == 1) {
$val = 0 - bindec(substr($bin,1)); // NEGATIVE
} else {
$val = bindec(substr($bin,1)); // POSITIVE
}
}
echo bin2int("00001101").'<br />';
echo bin2int("10001101");
http://php.net/manual/en/function.bindec.php