struct - Python unpack binary data, numeric of length 12 -


i have file big endian binaries. there 2 numeric fields. first has length 8 , second length 12. how can unpack 2 numbers?

i using python module struct (https://docs.python.org/2/library/struct.html) , works first field

num1 = struct.unpack('>q',payload[0:8]) 

but don't know how can unpack second number. if treat char(12), '\x00\xe3ac\x00\x00\x00\x06\x00\x00\x00\x01'.

thanks.

i think should create new string of bytes second number of length 16, fill last 12 bytes string of bytes hold number , first 4 ones zeros.

then decode bytestring unpack format >qq, let's numhi, numlo variables. then, final number that: number = numhi * 2^64 + numlo*. afair integers in python can (almost) large wish, have no problems overflows. that's rough idea, please comment if have problems writing in actual python code, i'll edit answer provide more help.

*^ in case math power, please use math.pow. alternatively, can use byte shift: number = numhi << 64 + numlo.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -