FutureWarning question

M

Mike

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?

Thanks,

-- Mike --
 
J

John Roth

Mike said:
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?

It doesn't have anything to do with bitwise operations. What it has to
do with is that 0xFFFF0000 is a negative number today, and it
will be a positive number in 2.4 As far as I can tell, the bitwise
operations are not affected. See PEP 237
(http://www.python.org/peps/pep-0237.html) for the explanation.

John Roth
 
A

A. Lloyd Flanagan

Mike said:
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

sys.maxint is the largest number that will fit into an int data type.
Although your constant is 32 bits, the high bit is set, so it gets
interpreted as a negative number.
-65536

In future versions of python, constants which are larger than
sys.maxint will not be interpreted as negative, but will automatically
be promoted to a long integer. The distinction between the two
integer types will pretty much disappear.

So, your constant will evaluate to a positive long integer
(4294901760L). Since you're using it as a bit mask, and not a number,
I don't think it will make a difference for your application. But the
compiler can't tell for sure, so it warns you anyway.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top