lib/danog/PHP/StructTools.php
public function decbin($number, $length)
    {
        $concat = '';
        if ($number < 0) {
            $negative = true;
            $number = -$number;
        } else {
            $negative = false;
        }
        while ($number > 0) {
            $curchar = $this->posmod($number, 2);
            $concat = $curchar.$concat;
            $number = (($number - $curchar) / 2);
        }
        $concat = str_pad($concat, $length, '0', STR_PAD_LEFT);
        if ($negative) {
            $concat = $this->binadd($this->stringnot($concat), '1');
        }
        if (strlen($concat) == $length + 1 && $concat == str_pad('1', $length + 1, '0', STR_PAD_RIGHT)) {
            $concat = str_pad('', $length, '0');
        }
        if (strlen($concat) > $length) {
            trigger_error('Converted binary number '.$concat.' is too long ('.strlen($concat).' > '.$length.').');
        }

        return $concat;
    }
public function decbin($number, $length)
    {
        $concat = '';
        if ($number < 0) {
            $negative = true;
            $number = -$number;
        } else {
            $negative = false;
        }
        while ($number > 0) {
            $curchar = $this->posmod($number, 2);
            $concat = $curchar.$concat;
            $number = (($number - $curchar) / 2);
        }
        $concat = str_pad($concat, $length, '0', STR_PAD_LEFT);
        if ($negative) {
            $concat = $this->binadd($this->stringnot($concat), '1');
        }
        if (strlen($concat) == $length + 1 && $concat == str_pad('1', $length + 1, '0', STR_PAD_RIGHT)) {
            $concat = str_pad('', $length, '0');
        }
        if (strlen($concat) > $length) {
            trigger_error('Converted binary number '.$concat.' is too long ('.strlen($concat).' > '.$length.').');
        }

        return $concat;
    }
decbin.

Returns a string containing a big endian binary representation of the given decimal number.
Also pads binary number with zeros to match given $length

@param	$number		Decimal number to turn into binary
@param	$length		Length to reach through padding

@return binary version of the given number