lib/danog/PHP/StructTools.php
public function binadd($x, $y)
    {
        $maxlen = max(strlen($x), strlen($y));

        //Normalize lengths
        $x = str_pad($x, $maxlen, '0', STR_PAD_LEFT);
        $y = str_pad($y, $maxlen, '0', STR_PAD_LEFT);

        $result = '';
        $carry = 0;
        for ($i = $maxlen - 1; $i >= 0; $i--) {
            $r = (int) ($carry + $x[$i] + $y[$i]);

            $result = ($r & 1).$result;
            $carry = $r >> 1;
        }
        if ($carry != 0) {
            $result = '1'.$result;
        }

        return str_pad($result, $maxlen, '0', STR_PAD_LEFT);
    }
public function binadd($x, $y)
    {
        $maxlen = max(strlen($x), strlen($y));

        //Normalize lengths
        $x = str_pad($x, $maxlen, '0', STR_PAD_LEFT);
        $y = str_pad($y, $maxlen, '0', STR_PAD_LEFT);

        $result = '';
        $carry = 0;
        for ($i = $maxlen - 1; $i >= 0; $i--) {
            $r = (int) ($carry + $x[$i] + $y[$i]);

            $result = ($r & 1).$result;
            $carry = $r >> 1;
        }
        if ($carry != 0) {
            $result = '1'.$result;
        }

        return str_pad($result, $maxlen, '0', STR_PAD_LEFT);
    }
binadd.

Add two binary numbers

@param	$x First binary number
@param	$y Second binary number

@return sum of the two numbers