Bitrex Bitrex - 1 year ago 73
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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download