Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Answer

Post Timeline

added 2 characters in body
Source Link

According to the documentation, specifying the byte order removes any padding:

No padding is added when using non-native size and alignment, e.g. with ‘<’, ‘>’, ‘=’, and ‘!’.

Therefore, assuming you require little endian packing, the following gives the required output:

>>> struct.pack('<Hf', id1, i)
'\x01\x00\x18\x1c\x14?'
>>> struct.pack('<Hf', id1, i).encode("hex")
'0100181c143f'

Note the <. (3f can be encoded as ASCII ?, hence the replacement)

According to the documentation, specifying the byte order removes any padding:

No padding is added when using non-native size and alignment, e.g. with ‘<’, ‘>’, ‘=’, and ‘!’.

Therefore, assuming you require little endian packing, the following gives the required output:

>>> struct.pack('<Hf', id1, i)
'\x01\x00\x18\x1c\x14?'
>>> struct.pack('<Hf', id1, i).encode("hex")
'0100181c143f'

According to the documentation, specifying the byte order removes any padding:

No padding is added when using non-native size and alignment, e.g. with ‘<’, ‘>’, ‘=’, and ‘!’.

Therefore, assuming you require little endian packing, the following gives the required output:

>>> struct.pack('<Hf', id1, i)
'\x01\x00\x18\x1c\x14?'

Note the <. (3f can be encoded as ASCII ?, hence the replacement)

Source Link

According to the documentation, specifying the byte order removes any padding:

No padding is added when using non-native size and alignment, e.g. with ‘<’, ‘>’, ‘=’, and ‘!’.

Therefore, assuming you require little endian packing, the following gives the required output:

>>> struct.pack('<Hf', id1, i)
'\x01\x00\x18\x1c\x14?'
>>> struct.pack('<Hf', id1, i).encode("hex")
'0100181c143f'
lang-py

AltStyle によって変換されたページ (->オリジナル) /