开发者

Python: Convert from buffer of Structure object to unsiged integer

开发者 https://www.devze.com 2023-01-18 03:52 出处:网络
I\'m new to Python, so I was wondering how would I extract buffer to convert the whole buffer into one integer from a Structure object with the code defined below

I'm new to Python, so I was wondering how would I extract buffer to convert the whole buffer into one integer from a Structure object with the code defined below

g = 12463
h = 65342
i = 94854731
j = 9000
class Blah(Structure):
    _fields_ = [
                ("a", ctypes.c_int32, 17),
                ("b", ctypes.c_int32, 19),
                ("c", ctypes.c_int64, 54),
                ("d", ctypes.c_int64, 33)]

x = Bla开发者_开发问答h(g, h, i, j)

y = [an unsigned python integer from x]

Now, how do I get an integer for y when the size of Blah object's bytes buffer is natively larger than 64 bit?


Instead of using a ctypes structure, use bit shift operations to assemble the integer.

y = g << 160 + h << 128 + i << 64 + j
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号