471,351 Members | 1,468 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,351 software developers and data experts.

Dealing with hex

Is there an ideal approach to dealing with the FutureWarning about getting
the hex value of a negative int? I'm using zlib.crc32() which can return
a negative 32-bit int value, so for example print '%x' % zlib.crc32(
buffer ) generates the FutureWarning. I know I could jump through hoops
to coerce the int into a long that will have the same CRC, but is there some
particular recomendation for this (I looked at PEP 237, but there wasn't a
suggestion).
Jul 18 '05 #1
3 2634
On Wed, 10 Dec 2003 03:49:16 GMT, Matt Gerrans wrote:
Is there an ideal approach to dealing with the FutureWarning about getting
the hex value of a negative int? I'm using zlib.crc32() which can return
a negative 32-bit int value, so for example print '%x' % zlib.crc32(
buffer ) generates the FutureWarning. I know I could jump through hoops
to coerce the int into a long that will have the same CRC, but is there some
particular recomendation for this (I looked at PEP 237, but there wasn't a
suggestion).


Hoops? For example :
print "%x" % long( zlib.crc32( buffer ) )

That seems simple enough to me.

--
If your life is a hard drive,
Christ can be your backup.

www: http://dman13.dyndns.org/~dman/ jabber: dm**@dman13.dyndns.org
Jul 18 '05 #2
Derrick 'dman' Hudson <dm**@dman13.dyndns.org> wrote in message news:<6c************@dman13.dyndns.org>...
On Wed, 10 Dec 2003 03:49:16 GMT, Matt Gerrans wrote:
Is there an ideal approach to dealing with the FutureWarning about getting
the hex value of a negative int? I'm using zlib.crc32() which can return
a negative 32-bit int value, so for example print '%x' % zlib.crc32(
buffer ) generates the FutureWarning. I know I could jump through hoops
to coerce the int into a long that will have the same CRC, but is there some
particular recomendation for this (I looked at PEP 237, but there wasn't a
suggestion).


Hoops? For example :
print "%x" % long( zlib.crc32( buffer ) )

That seems simple enough to me.


Or if you wanted the old semantics:

def unsigned(n):
return n & 0xFFFFFFFFL

print "%x" % unsigned(zlib.crc32(buffer))
Jul 18 '05 #3
Derrick 'dman' Hudson wrote:
Hoops? For example :
print "%x" % long( zlib.crc32( buffer ) )

That seems simple enough to me.
Simple indeed. In fact it's so simple it doesn't work:
print "%x" % long( zlib.crc32('test') )
-278081f4

Dan Bishop wrote: Or if you wanted the old semantics:

def unsigned(n):
return n & 0xFFFFFFFFL

print "%x" % unsigned(zlib.crc32(buffer))


This avoids the FutureWarning, but the PEP mentions that the L-suffix
notation will also be phased out, so I wanted to avoid that in the solution
and that can be done like this:

def unsigned32(n): return n & 4294967295

since the large decimal of 0xffffffff value will automatically be a long.

It seems kind of clunky to have to throw this extra function call into the
mix whenever dealing with 32-bit values. I don't think 32-bit values will
be made obsolete by 64-bit systems for quite a while to come. This
particular update to Python seems a little pie-in-the-sky and un-pragmatic.
Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Fazer | last post: by
5 posts views Thread by Tom Willis | last post: by
44 posts views Thread by flyingfred0 | last post: by
1 post views Thread by Igor Kramarsich - EDIT | last post: by
16 posts views Thread by pereges | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.