![]() |
| Home About Us Services Clients Resources Blog Careers Orderbox™ | contact us Site map links |
Casting Python integers into signed 32-bit equivalents
When implementing bit-twiddling routines in C/C++, one frequently
takes for granted the implicit convertibility between signed and
unsigned values of the same bit pattern and bitwidth. For example,
The following routine will take any integer value up
to The return value is guaranteed to be
def int32(x):
if x>0xFFFFFFFF:
raise OverflowError
if x>0x7FFFFFFF:
x=int(0x100000000-x)
if x<2147483648:
return -x
else:
return -2147483648
return x
© 2008 by Andy Sy |
|
Web Development / Rich Internet Applications (RIA) Development
Programming LanguagesPlatformsDatabase Development
|
| © 2003-2008 Neotitans Technologies Inc. | contact/hire us |