How to get rid of FutureWarning: hex/oct constants...
"Martin v. Löwis"
martin at v.loewis.de
Sun Mar 27 05:48:46 EST 2005
Bengt Richter wrote:
> >>> hex(-2*0x40000000+0x40047a80)
> __main__:1: FutureWarning: hex()/oct() of negative int will return a signed string in Python 2.4
> and up
> '0xc0047a80'
>
> That "signed string" is a unary minus expression using an absolute value forced by the inadequacy
> of the literal representation syntax.
> IOW, IMO '-' + hex_literal_of(abs(x)) is not a decent hex_literal_of(-x) !!
This has been discussed over and over, but since you bring it up again:
There are no hex literals for negative numbers, just as there are no
decimal literals for negative number. A literal, by nature, in any
base, is non-negative.
If you disagree: Is 0xFFF6 a positive or a negative number?
Regards,
Martin
More information about the Python-list
mailing list