[issue30571] Add integer formatting code for fixed-width signed arithmetic (2's complement)

2017-06-12 Thread Lisa Roach
Lisa Roach added the comment: I can't see the drawback of being able to format two's complement easily, isn't it more common to represent negative binary numbers in two's complement form? I find the - sign a little odd myself. I agree with the idea of using "!" with the precision to represent

[issue30571] Add integer formatting code for fixed-width signed arithmetic (2's complement)

2017-06-12 Thread Antoine Pitrou
Antoine Pitrou added the comment: The format code space is already crowded, and it isn't immediately obvious that '08B' will format the 2's complement representation of the number, as opposed to '08b' which prepends a sign bit. Not to mention that, as Raymond remarked, we cannot use the same

[issue30571] Add integer formatting code for fixed-width signed arithmetic (2's complement)

2017-06-12 Thread Stefan Krah
Stefan Krah added the comment: To expand on what Mark said: If the proposed format code implicitly gives these results ... >>> format(12 % 2**8, '08b') '1100' >>> format(-12 % 2**8, '08b') '0100' ..., would students not expect that these two operations have the same result? >>> 0b111

[issue30571] Add integer formatting code for fixed-width signed arithmetic (2's complement)

2017-06-12 Thread Mark Dickinson
Changes by Mark Dickinson : -- nosy: -mark.dickinson ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://m

[issue30571] Add integer formatting code for fixed-width signed arithmetic (2's complement)

2017-06-12 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: > The idea is that modifier (such as "!" would require a width argument (the > signed representation only make sense in fixed width concepts as every > assembly language programmer knows). Its presence would also imply the "0". I would use the precision for

[issue30571] Add integer formatting code for fixed-width signed arithmetic (2's complement)

2017-06-12 Thread Raymond Hettinger
Raymond Hettinger added the comment: This is a recurring need in my teaching of Python to hardware engineers. The whole point of having a binary format code is to show which bits are set. For negative values, that need is not being served by the current option. And it makes it awkward when

[issue30571] Add integer formatting code for fixed-width signed arithmetic (2's complement)

2017-06-12 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Concur with Mark. Similar issues already were raised multiple times on mailing lists and the conclusion is that explicit wrapping integers to specific range is better. Different behavior for integers out of range is needed in different applications. ---

[issue30571] Add integer formatting code for fixed-width signed arithmetic (2's complement)

2017-06-12 Thread Mark Dickinson
Mark Dickinson added the comment: -1 from me. Using `format(x % 2**8, '08b')` seems both short enough to be easy to use, and long enough to remind one that there's something a little bit unnatural going on here, given that two's complement isn't something that makes sense for arbitrary-sized i

[issue30571] Add integer formatting code for fixed-width signed arithmetic (2's complement)

2017-06-11 Thread Raymond Hettinger
Changes by Raymond Hettinger : -- assignee: -> lisroach nosy: +lisroach ___ Python tracker ___ ___ Python-bugs-list mailing list Unsu

[issue30571] Add integer formatting code for fixed-width signed arithmetic (2's complement)

2017-06-06 Thread Cheryl Sabella
Changes by Cheryl Sabella : -- nosy: +csabella ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.pyt

[issue30571] Add integer formatting code for fixed-width signed arithmetic (2's complement)

2017-06-04 Thread Raymond Hettinger
New submission from Raymond Hettinger: The current 'b' formatting code in inconvenient for emulating, demonstrating, and teaching two's complement arithmetic. The problem is that negative inputs are always formatted with a minus sign. I propose that some formatting code be provided for fixed