[New-bugs-announce] [issue25999] Add support of native number in bin()

SonokoMizuki report at bugs.python.org
Sun Jan 3 06:45:05 EST 2016


New submission from SonokoMizuki:

Add support of negative number in bin().
Currently, bin(-5) returns '-0b101', It is not intuitive.
I think bin() should return two's complement.

I suggest new bin().
New second argument is bit size.
if first argument is negative number and bit size is given, bin() will return two's complement.

example)
>>> bin(12)
'0b1100'
>>> bin(-12)
'-0b1100'
>>> bin(-12,8)
'0b11110100'
>>> bin(-12,3) # if not enough bit size, bin will return value as usual.
'-0b100'

----------
components: Argument Clinic
messages: 257408
nosy: larry, mizuki
priority: normal
severity: normal
status: open
title: Add support of native number in bin()
type: behavior
versions: Python 2.7, Python 3.2, Python 3.3, Python 3.4, Python 3.5, Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue25999>
_______________________________________


More information about the New-bugs-announce mailing list