473,472 Members | 1,728 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 2732
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.