471,073 Members | 1,391 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

a 32 bit number to integer

Hi,

In python 2.0, this number was an integer:
0x88776655

but in python 2.4 it is a long (every number > 0x7fffffff it is a long)

in python 2.4, is there a way to convert that number to a integer
(notice that it only occupies 32 bits) ?
thanks,
riq.

Jan 24 '06 #1
2 2199
Ricardo Quesada <li***@core-sdi.com> writes:
0x88776655

but in python 2.4 it is a long (every number > 0x7fffffff it is a long)

in python 2.4, is there a way to convert that number to a integer
(notice that it only occupies 32 bits) ?


It would be -2005440939 but that's maybe not what you want.
Jan 24 '06 #2
On Tue, 24 Jan 2006 13:23:05 -0300 in comp.lang.python, Ricardo
Quesada <li***@core-sdi.com> wrote:
Hi,

In python 2.0, this number was an integer:
0x88776655

but in python 2.4 it is a long (every number > 0x7fffffff it is a long)

in python 2.4, is there a way to convert that number to a integer
(notice that it only occupies 32 bits) ?


Well, the sign bit's gonna be set no matter what. But the following
might work for you...
def short(x): return int(0x80000000 - x)

x = short(0x88776655)
x -142042709 "%x"%x '-8776655'


Regards,
-=Dave

--
Change is inevitable, progress is not.
Jan 24 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Shuffs | last post: by
10 posts views Thread by chanma | last post: by
2 posts views Thread by Alex Buell | last post: by
4 posts views Thread by SweetLeftFoot | last post: by
1 post views Thread by Smalley | last post: by
reply views Thread by leo001 | 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.