2

Unfortunately I don't understand the byte size calculation of the struct python module. I use this documentation when encoding my values.

import struct
struct.calcsize('H') # == 2
struct.calcsize('d') # == 8

but

struct.calcsize('Hd') # == 16 != 8+2

using the encoding together requires 16 bytes instead of 10

What could be/is the reason for this? Thanks!

asked Feb 20, 2020 at 13:13
2
  • See the grey "note" box at the beginning of your linked documentation page about alignment. Commented Feb 20, 2020 at 13:23
  • Does this answer your question? Python struct giving incorrect length Commented Feb 2, 2024 at 10:22

1 Answer 1

1

Maybe this can help; Python struct giving incorrect length

struct.calcsize('=Hd')
answered Feb 20, 2020 at 13:28
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you and thanks also to @Michael Butscher for the hint.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.