Disagree with proposed 2.4 behavior for %x formatting of signed ints

  • Thread starter Letbetter, Jason
  • Start date
L

Letbetter, Jason

Consider the following:
__main__:1: FutureWarning: %u/%o/%x/%X of negative int will return a signed
string in Python 2.4 and up
0xC1F2C703

If I understand the warning correctly then the following would happen after
2.4:
-1041053949

I think the printf format should take precedence. It is obvious that the
programmer wants a hex number displayed.
 
T

Tim Roberts

Letbetter said:
Consider the following:

__main__:1: FutureWarning: %u/%o/%x/%X of negative int will return a signed
string in Python 2.4 and up
0xC1F2C703

If I understand the warning correctly then the following would happen after
2.4:

-1041053949

You do not understand correctly. This is what will happen:
0x-3E0D38FD

It will still be a hex number, but the sign will be honored, producing
possibly unexpected results.
I think the printf format should take precedence. It is obvious that the
programmer wants a hex number displayed.

You'll get a hex number. You'll just get a sign with it.

I've started three different times to post a message complaining that the
changes in 2.3 and the changes proposed in 2.4 are taking Python farther
and farther away from the cool system-level binary manipulation tool I
often use it for, but every time I get part way through it, I realize that
the changes do make sense from a consistency point of view, and that it
doesn't take that much more work to do it "right".
 
B

Bengt Richter

Actually, what *will* happen is

-0x3E0D38FD
Really? In that case, would

print "@#%08X" % -1041053949

produce

-@#3E0D38FD

??
Indeed. You can still do all binary manipulations that you want to do.
But reasonably?

Regards,
Bengt Richter
 

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,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top