Packing data of different sizes into a list of unsigned ints
问题 I have a set of data that represents a hardware structure that I need to manipulate in python. The real structure is 4 KB in size...I'll just whip up a quick example: Byte(s) Value 0-1 0x0102 2-3 0x0304 4-23 "AStrWith20Characters" 24-63 "WoahThisStringHas40CharactersItIsHuge!!!" 64-71 "Only8Chr" 72-74 0x050607 74 0x08 75-127 0x00 (padding) The idea is I pack this structure up into a list of 32 bit Ints, pass the list off to another function, and that function then writes the whole shebang out