Re: Can this code go faster?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux