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
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php