# struct

• If I convert a character to bytes I get 1 byte

``````>>> bytes=struct.pack('s', 'F'); print(bytes, len(bytes))
b'F' 1
``````

If I convert an epoch to bytes I get 4 bytes

``````>>> bytes=struct.pack('I', 1611017052); print(bytes, len(bytes))
b'\\+\x06`' 4
``````

How come when I do both together I get 8 instead of 4+1=5 ??

``````bytes=struct.pack('sI', 'F', 1611017052); print(bytes, len(bytes))
b'F\x00\x00\x00\\+\x06`' 8
``````

but this way I get the 5 I expect?

``````>>> bytes=struct.pack('Is', 1611017052, 'F'); print(bytes, len(bytes))
b'\\+\x06`F' 5

``````

why is a different packing sequence giving different numbers of bytes?

• @Gijs tnx

• This is related to the byte-alignment in struct, aligning to the longest used data type. As `I` is 4 bytes long, and `s` is 1 byte, the total length of the structure will be either 5 or 8, depending on the alignment. As you put `sI`, we would expect the character on the first index, and the integer on the second index, however, the controller knows these integers take 4 bytes, and expects the integer to start on the 5th index, as the 1st index already contains a character, therefor you get 3 null bytes after the character. This is expected behaviour

You can disable the alignment with an `<` or `>` sign in the type definition
{"ft_lang_label":"__label__en","ft_lang_prob":0.72410434,"math_prob":0.7693472,"size":1224,"snap":"2022-27-2022-33","text_gpt3_token_len":363,"char_repetition_ratio":0.13360655,"word_repetition_ratio":0.0,"special_character_ratio":0.31535947,"punctuation_ratio":0.13584906,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9878485,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-08-18T04:28:09Z\",\"WARC-Record-ID\":\"<urn:uuid:ff9b9443-0c0a-449e-bfe3-db0ec5ede59c>\",\"Content-Length\":\"46876\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:3933ff9e-a306-4a4b-81d0-e963a6047f1d>\",\"WARC-Concurrent-To\":\"<urn:uuid:d3549a57-8cc2-43df-9566-235bc62b30f3>\",\"WARC-IP-Address\":\"18.196.25.208\",\"WARC-Target-URI\":\"https://forum.pycom.io/topic/6761/struct\",\"WARC-Payload-Digest\":\"sha1:CQANPJUA3JSSVTU4W3AWE3RHIQB3QKMJ\",\"WARC-Block-Digest\":\"sha1:DGF5MJZQVFIG3PCLA3OL7H5SVKDFXQNH\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-33/CC-MAIN-2022-33_segments_1659882573163.7_warc_CC-MAIN-20220818033705-20220818063705-00402.warc.gz\"}"}