a 32 bit number to integer
Dave Hansen
iddw at hotmail.com
Tue Jan 24 11:58:31 EST 2006
On Tue, 24 Jan 2006 13:23:05 -0300 in comp.lang.python, Ricardo
Quesada <lists at 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.
More information about the Python-list
mailing list