numpy 1.22.4 Pypi GitHub Homepage
Other Docs
NotesParametersReturnsBackRef
binary_repr(num, width=None)

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 . A N-bit two's-complement system can represent every integer in the range $-2^{N-1}$ to $+2^{N-1}-1$ .

Notes

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

Parameters

num : int

Only an integer decimal number can be used.

width : int, optional

The length of the returned string if :None:None:`num` is positive, or the length of the two's complement if :None:None:`num` is negative, provided that :None:None:`width` is at least a sufficient number of bits for :None:None:`num` to be represented in the designated form.

If the :None:None:`width` value is insufficient, it will be ignored, and :None:None:`num` will be returned in binary (:None:None:`num` > 0) or two's complement (:None:None:`num` < 0) form with its width equal to the minimum number of bits needed to represent the number in the designated form. This behavior is deprecated and will later raise an error.

deprecated

Returns

bin : str

Binary representation of :None:None:`num` or two's complement of :None:None:`num`.

Return the binary representation of the input number as a string.

See Also

base_repr

Return a string representation of a number in the given base system.

bin

Python's built-in binary representation generator of an integer.

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=3)
'101'
>>> np.binary_repr(-3, width=5)
'11101'
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

dask.array.ufunc.bitwise_or dask.array.ufunc.bitwise_xor numpy.ma.core.bitwise_and numpy.ma.core.bitwise_xor numpy.ma.core.bitwise_or dask.array.ufunc.invert numpy.base_repr dask.array.ufunc.bitwise_and numpy.binary_repr

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /numpy/core/numeric.py#1940
type: <class 'function'>
Commit: