python - 使用 Python ctypes 在整数格式之间进行转换

标签 python casting ctypes

如何使用 ctypes“cast”函数将一种整数格式转换为另一种整数格式,以获得与 C 中相同的效果:

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

?

最佳答案

>>> cast((c_int*1)(1), POINTER(c_uint)).contents
c_uint(1L)
>>> cast((c_int*1)(-1), POINTER(c_uint)).contents
c_uint(4294967295L)

关于python - 使用 Python ctypes 在整数格式之间进行转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17166334/

相关文章:

python - 如何使用 2D Numpy 数组放置 pop/append?

python - 使用 python 从文件中的字符串中获取字母频率

c - 函数指针,如何转换?

c# - 如何通过 .Net Web 服务使用相同的域实体?

mysql - MySQL 5.5:当我对BIT数据类型使用“CONV”时,为什么有任何基础工作

python - 我无法使用 ctypes cuda 获得输出数字

python-daemon 阻止对 ctypes 链接的 C 用户库的 ioctl 调用

python - python中如何操作C函数返回的C类型指针?

python - 2个列表上的字符串比较

python - Python3 中类内部的命名空间