You are here: Re: Can this code go faster? « PHP « IT news, forums, messages
Re: Can this code go faster?

Posted by Jason Barnett on 10/11/70 11:14

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация