Bitrex Bitrex - 1 year ago 53
Python Question

Casting between integer formats with Python ctypes

How can I use the ctypes "cast" function to cast one integer format to another, to obtain the same effect as in C:

int var1 = 1;
unsigned int var2 = (unsigned int)var1;


Answer Source
>>> cast((c_int*1)(1), POINTER(c_uint)).contents
>>> cast((c_int*1)(-1), POINTER(c_uint)).contents