public static function int2bytes($len, $int = 0, $l = false)
    {
        $hexstr = dechex($int);

        if ($len === null) {
            if (strlen($hexstr) % 2) {
                $hexstr = "0" . $hexstr;
            }
        } else {
            $hexstr = str_repeat('0', $len * 2 - strlen($hexstr)) . $hexstr;
        }

        $bytes = strlen($hexstr) / 2;
        $bin   = '';

        for ($i = 0; $i < $bytes; ++$i)
        {
            $bin .= chr(hexdec(substr($hexstr, $i * 2, 2)));
        }

        return $l ? strrev($bin) : $bin;
    }
public static function int2bytes($len, $int = 0, $l = false)
    {
        $hexstr = dechex($int);

        if ($len === null) {
            if (strlen($hexstr) % 2) {
                $hexstr = "0" . $hexstr;
            }
        } else {
            $hexstr = str_repeat('0', $len * 2 - strlen($hexstr)) . $hexstr;
        }

        $bytes = strlen($hexstr) / 2;
        $bin   = '';

        for ($i = 0; $i < $bytes; ++$i)
        {
            $bin .= chr(hexdec(substr($hexstr, $i * 2, 2)));
        }

        return $l ? strrev($bin) : $bin;
    }
public static function int2bytes ( $ len , $ int = 0 , $ l = false ) { $ hexstr = dechex ( $ int ) ; if ( $ len === null ) { if ( strlen ( $ hexstr ) % 2 ) { $ hexstr = "0" . $ hexstr ; } } else { $ hexstr = str_repeat ( '0' , $ len * 2 - strlen ( $ hexstr ) ) . $ hexstr ; } $ bytes = strlen ( $ hexstr ) / 2 ; $ bin = '' ; for ( $ i = 0 ; $ i < $ bytes ; ++ $ i ) { $ bin .= chr ( hexdec ( substr ( $ hexstr , $ i * 2 , 2 ) ) ) ; } return $ l ? strrev ( $ bin ) : $ bin ; }
Converts integer to binary string.

@param int $len
@param int $int
@param bool $l Little-endian, defaults to false.
@return string
Converts integer to binary string .