How to convert signed 32-bit int to unsigned 32-bit int?

自作多情 提交于 2019-11-30 20:07:26

Not sure if it's "nicer" or not...

import ctypes

def int32_to_uint32(i):
    return ctypes.c_uint32(i).value

using numpy for example:

import numpy
result = numpy.uint32( numpy.int32(myval) )

or even on arrays,

arr = numpy.array(range(10))
result = numpy.uint32( numpy.int32(arr) )
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!