FutureWarning question

Robert Brewer fumanchu at amor.org
Tue Apr 13 02:20:37 EDT 2004


Mike wrote:
> I ran across the message below in 2.3.2 today. These are the 
> lines of code:
> 
>    402: if m1_hi >> 15 & 0x0001 == 1:
>    403:    m1_hi = m1_hi | 0xFFFF0000
>    404: if m1_lo >> 15 & 0x0001 == 1:
>    405:    m1_lo = m1_lo | 0xFFFF0000
> 
> This is the warning message:
> 
>    pwg.py:403: FutureWarning: hex/oct constants > sys.maxint 
> will return 
>    positive values in Python 2.4 and up
>       m1_hi = m1_hi | 0xFFFF0000
>    pwg.py:405: FutureWarning: hex/oct constants > sys.maxint 
> will return 
>    positive values in Python 2.4 and up
>       m1_lo = m1_lo | 0xFFFF0000
> 
> m1_hi and m1_lo are 32 bit values read from a file. It's not 
> clear to me
> what the warning message means. The only constant is 
> 0xffff0000; does the
> message mean that the result of the OR operation won't be 
> what I think it
> is? Can anyone elucidate?

Try typing at an interactive prompt:

>>> 0xffff0000
<interactive input>:1: FutureWarning: hex/oct constants > sys.maxint
will return positive values in Python 2.4 and up
<interactive input>:1: FutureWarning: hex/oct constants > sys.maxint
will return positive values in Python 2.4 and up
<interactive input>:1: FutureWarning: hex/oct constants > sys.maxint
will return positive values in Python 2.4 and up
-65536

...as you can see, Python 2.3.2 interprets 0xffff0000 as a negative int.
The warning is saying that in Python 2.4 and following, such a hex value
will be positive (e.g. 4294901760L), rather than negative (-65536).


Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org




More information about the Python-list mailing list