On 07/11/2016 01:27 PM, Ian Kelly wrote: > On Mon, Jul 11, 2016 at 12:54 PM, Terry Reedy <tjre...@udel.edu> wrote: >> In any case, I think it an improvement to say that '0x00123' has a field >> width of 7 rather than a 'precision' of 5. >> >>>>> '{:#07x}'.format(0x123) # specifiy field width >> '0x00123' >>>>> "%#0.5x" % 0x123 # specify int precision >> '0x00123' > > It occurs to me now that this does create a challenge if the format is > meant to support negative numbers as well: > >>>> '%#0.5x' % -0x123 > '-0x00123' >>>> '{:#07x}'.format(-0x123) > '-0x0123'
I'm not sure I've ever seen a negative hex number in the wild. Usually when I view a number in hex I am wanting the raw representation. -0x123 with a width of 7 would be 0xFFEDD -- https://mail.python.org/mailman/listinfo/python-list