Emulate uint32_t in Python? -


i trying port function c python , make easy debug, i'd prefer performed same cpu word-size limited operations compare intermediate results. in other words, i'd like:

a = unsignedboundedint(32, 399999) b = unsignedboundedint(32, 399999) print(a*b) # prints 1085410049 (159999200001 % 2**32) 

what's best way achieve operations (including bitwise shifts) work in c?

you can try using ctypes.uint_32 bound results you:

>>> import ctypes >>> print ctypes.c_uint32(399999 * 399999).value 1085410049 

alternatively can use numpy's data types:

>>> import numpy np >>> = np.uint32(399999) >>> b = np.uint32(399999) >>> * b __main__:1: runtimewarning: overflow encountered in uint_scalars 1085410049 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

java.util.scanner - How to read and add only numbers to array from a text file -

iphone - Three second countdown in cocos2d -