[issue25999] Add support of native number in bin()
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) '0b0100' >>> 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 <http://bugs.python.org/issue25999> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue25999] Add support of native number in bin()
SonokoMizuki added the comment: It is nice solution. I can get negative number all right. thanks but, I feel bad that bin(-5) returns '-0b101' sorry -- ___ Python tracker <http://bugs.python.org/issue25999> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue25999] Add support of native number in bin()
SonokoMizuki added the comment: That's right. currently python can not distinguish positive number or negative number. >>> a = bin(-5,10) >>> int(a,2) 1019 I think reason of ambiguity is decode function( int() ). So, I suggest new decode function. (example) >>> b2i('0b1011',negative=True) -5 >>> b2i('0b1011',negative=False) 11 ( I do not know whether it is good to add special function for binary..., sorry) -- ___ Python tracker <http://bugs.python.org/issue25999> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue25999] Add support of native number in bin()
SonokoMizuki added the comment: I see. I grasp to write own function is best. thanks (^-^) -- ___ Python tracker <http://bugs.python.org/issue25999> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue25999] Add support of negative number in bin()
Changes by SonokoMizuki : -- title: Add support of native number in bin() -> Add support of negative number in bin() ___ Python tracker <http://bugs.python.org/issue25999> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com