def binary_repr(num, width=None):
<EOL>sign = '<STR_LIT>'<EOL>if num < <NUM_LIT:0>:<EOL><INDENT>if width is None:<EOL><INDENT>sign = '<STR_LIT:->'<EOL>num = -num<EOL><DEDENT>else:<EOL><INDENT>num = <NUM_LIT:2>**width + num<EOL><DEDENT><DEDENT>elif num == <NUM_LIT:0>:<EOL><INDENT>return '<STR_LIT:0>'*(width or <NUM_LIT:1>)<EOL><DEDENT>ostr = hex(num)<EOL>bin = '<STR_LIT>'.join([_lkup[ch] for ch in ostr[<NUM_LIT:2>:]])<EOL>bin = bin.lstrip('<STR_LIT:0>')<EOL>if width is not None:<EOL><INDENT>bin = bin.zfill(width)<EOL><DEDENT>return sign + bin<EOL>
Return the binary representation of the input number as a string.

For negative numbers, if width is not given, a minus sign is added to the
front. If width is given, the two's complement of the number is
returned, with respect to that width.

In a two's-complement system negative numbers are represented by the two's
complement of the absolute value. This is the most common method of
representing signed integers on computers [1]_. A N-bit two's-complement
system can represent every integer in the range
:math:`-2^{N-1}` to :math:`+2^{N-1}-1`.

Parameters
----------
num : int
    Only an integer decimal number can be used.
width : int, optional
    The length of the returned string if `num` is positive, the length of
    the two's complement if `num` is negative.

Returns
-------
bin : str
    Binary representation of `num` or two's complement of `num`.

See Also
--------
base_repr: Return a string representation of a number in the given base
           system.

Notes
-----
`binary_repr` is equivalent to using `base_repr` with base 2, but about 25x
faster.

References
----------
.. [1] Wikipedia, "Two's complement",
    http://en.wikipedia.org/wiki/Two's_complement

Examples
--------
>>> np.binary_repr(3)
'11'
>>> np.binary_repr(-3)
'-11'
>>> np.binary_repr(3, width=4)
'0011'

The two's complement is returned when the input number is negative and
width is specified:

>>> np.binary_repr(-3, width=4)
'1101'