[issue25999] Add support of native number in bin()

2016-01-03 Thread Larry Hastings
Larry Hastings added the comment: Even if this was a good idea, it's too late to change the behavior of the builtin function. -- resolution: -> rejected stage: -> resolved status: open -> closed ___ Python tracker

[issue25999] Add support of native number in bin()

2016-01-03 Thread SonokoMizuki
SonokoMizuki added the comment: I see. I grasp to write own function is best. thanks (^-^) -- ___ Python tracker ___ ___ Python-bugs-l

[issue25999] Add support of native number in bin()

2016-01-03 Thread Eryk Sun
Eryk Sun added the comment: bin() returns a Python literal, which thankfully requires an explicit sign. 2's complement literals would be prone to human error. If you want 2's complement, you can write your own function. For example: def mybin(number, nbits=None, *, signed=True): if

[issue25999] Add support of native number in bin()

2016-01-03 Thread SonokoMizuki
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)

[issue25999] Add support of native number in bin()

2016-01-03 Thread Peter Otten
Peter Otten added the comment: How would you disambiguate -1 and (for example) 2**64-1 on a 64-bit machine? Python's int is not limited to a specific number of bits. -- nosy: +peter.otten ___ Python tracker __

[issue25999] Add support of native number in bin()

2016-01-03 Thread SonokoMizuki
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 ___ ___

[issue25999] Add support of native number in bin()

2016-01-03 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Use bin(n & (2**bitsize-1)). -- nosy: +serhiy.storchaka ___ Python tracker ___ ___ Python-bugs-lis

[issue25999] Add support of native number in bin()

2016-01-03 Thread SilentGhost
Changes by SilentGhost : -- components: +Interpreter Core -Argument Clinic versions: -Python 2.7, Python 3.2, Python 3.3, Python 3.4, Python 3.5 ___ Python tracker ___ _

[issue25999] Add support of native number in bin()

2016-01-03 Thread SonokoMizuki
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