tags:

views:

54

answers:

1

Hi all,

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 = Blah(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?

A: 

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

y = g << 160 + h << 128 + i << 64 + j
Forrest
since I'm going to have to pass this to C, is bitshift in python a good way to ensure exact bits to be passed to C program when the structure is not just integer?
SUCM
No, use a ctypes struct for more complex things, and do `ctypes.string_at(ctypes.addressof(x), ctypes.sizeof(x))`
Forrest