Official website Symbol Description: https://docs.python.org/3/library/struct.html#format-characters
Splits a 32-bit unsigned int into 4 bytes: pack
Import Structprint (Struct.pack (' >i ', 10240099)) # ' > ' represents the conversion to Big-endian, that is, the network byte order, ' I ' means ' 10240099 ' is a 4 byte unsigned integer # number of shapes D = struct.pack (' <i ', 10240099) # ' < ' for conversion to Little-endianprint (d)
Operation Result:
B ' \x00\[email protected] ' b ' [email protected]\x9c\x00 '
Combine the corresponding number of digits into one count: unpack
A = Struct.pack (' >i ', 10240099) b = struct.unpack (' >i ', a) #将a bytes are converted to a 4-byte unsigned integer by Big-endian print (b) c = struct.un Pack (' >ih ', b ' \xf0\xf0\xf0\xf0\x80\x80 ') print (c)
Operation Result:
(10240099,) (4042322160, 32896) # (I, H)
Python byte conversion: struct