lib/danog/PHP/StructTools.php
public function bindec($binary, $unsigned = true)
    {
        $decimal = 0;
        if (!$unsigned && $binary[0] == '1') {
            $binary = $this->binadd($this->stringnot($binary), '1');
            $negative = true;
        } else {
            $negative = false;
        }

        foreach (str_split(strrev($binary)) as $n => $bit) {
            if ($bit == 1) {
                $decimal += pow(2, $n);
            }
        }

        return $negative ? -$decimal : $decimal;
    }
public function bindec($binary, $unsigned = true)
    {
        $decimal = 0;
        if (!$unsigned && $binary[0] == '1') {
            $binary = $this->binadd($this->stringnot($binary), '1');
            $negative = true;
        } else {
            $negative = false;
        }

        foreach (str_split(strrev($binary)) as $n => $bit) {
            if ($bit == 1) {
                $decimal += pow(2, $n);
            }
        }

        return $negative ? -$decimal : $decimal;
    }
bindec.

Converts a binary number to a decimal.

@param	$binary		binary number to turn into decimal
@param	$unsigned	if set to false will interpret binary string as signed

@return decimal version of the given number