473,236 Members | 1,668 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,236 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 2720
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Fazer | last post by:
Hello, I have the following code: #!/usr/local/bin/python import cgi import Cookie C = Cookie.SimpleCookie() C = "f"
5
by: Tom Willis | last post by:
How are the expert pythoneers dealing with config files? Is there anything similair to .net's config files or java's .properties? A quick search on google didn't return anything that looked...
44
by: flyingfred0 | last post by:
A small software team (developers, leads and even the manager when he's had time) has been using (wx)Python/PostgreSQL for over 2 years and developed a successful 1.0 release of a client/server...
1
by: news.microsoft.com | last post by:
Hello group, My goal is to attach an image over another image. Top image should be transparent so the back image is visible through the top one. Bellow is a test code in VB.NET. You need to...
2
by: malcolm | last post by:
Hello, We have a robust (.NET 1.1 c# winforms) client-server application that utilizes many typed DataSets, typed DataTables and typed DataRows. Our application is a series of windows and popup...
1
by: Igor Kramarsich - EDIT | last post by:
I'm having problems dealing with dates in my queries/SQL code. I need a search digit date. In form define date field without format I receive results. But I go to define date filed with short date...
16
by: pereges | last post by:
ok so i have written a program in C where I am dealing with huge data(millions and lots of iterations involved) and for some reason the screen tends to freeze and I get no output every time I...
2
by: none | last post by:
All, I was wondering is their a way of dealing with subStatusCode's with in the webconfig file? I unfortunately don't have access to anything other then webconfig and qould perfer to set in code...
0
AmberJain
by: AmberJain | last post by:
Windows Autorun FAQs: Programs dealing with autoruns Linked from the Original article- "Windows Autorun FAQs: Description". Que: Can you list programs that help me to view/modify the autoruns...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

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.