1

I want to pack 128 byte of different data types. The structure as follows

4 bytes - 0x12345678,

2 bytes - 0x1234,

120 bytes - 0x00 (repeats 120 times),

2 byte - 0x99 ,

I tried with below code but fails

struct.pack('<LH120BH',0x12345678,0x1234,0x00,0x99 )

gives error

Traceback (most recent call last):
File "<pyshell#10>", line 1, in <module>
struct.pack('<LH120BH',0x12345678,0x1234,0x00,0x99 )
struct.error: pack expected 123 items for packing (got 4)

pls help me. Thanks in advane

1 Answer 1

1

You may need to pack 0x00 in to an array if you want it to repeat 120 times and unpack it when call struct.pack, maybe something like this:

struct.pack('<LH120BH',0x12345678,0x1234,*[0x00] * 120,0x99)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.