Python: Convert from buffer of Structure object to unsiged integer
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
精彩评论