Reference Links: https://www.liaoxuefeng.com/wiki/1016959663602400/1017685387246080
When a Python byte characters are converted to data types, Python does not provide the type of specialized data processing bytes, but Python provides a Struct module bytes and other binary data type conversion
pack (), the type of arbitrary data bytes into a data type
>>> import struct >>> struct.pack('>I', 10240099) b'\x00\x9c@c'
pack
The first parameter is the processing instruction, '>I'
meaning that:
>
Represents a byte order is big-endian, network order i.e., I
represents a 4-byte unsigned integer.
Behind the number of parameters to be consistent and processing instructions. If they are not being given
>>> struct.pack('I','2') Traceback (most recent call last): File "<stdin>", line 1, in <module> struct.error: required argument is not an integer >>>
unpack
Put bytes
into the corresponding data types:
>>> struct.unpack('>IH', b'\xf0\xf0\xf0\xf0\x80\x80') (4042322160, 32896)
H represents a two byte unsigned integer,
c character represents one byte
Therefore, although not suitable for coding Python underlying operating byte streams, but performance is not required in place of using struct
more convenient .
struct
Module-defined data types can refer to the official Python documentation: https://docs.python.org/3/library/struct.html#format-characters
Small end storage
Reference Links: https://blog.csdn.net/favory/article/details/4441361
And the address data stored in the memory related to
Small end storage: less significant bytes stored in a lower memory address , higher significant byte stored in high address memory
Big-endian storage: higher significant byte is stored in a lower memory address , the lower significant byte stored in high address memory
Why is there a higher significant byte, and a lower effective byte distinguish it?
This is because the current computer system, we are bytes, each address unit corresponds to a byte, a byte is 8bit, while the C language in addition to the char 8bit, there's 16bit short type, but also with long 32bit types of (different compilers is not the same), then join us to store a length 32bit integer of:
(Since one address unit is 8bit, the length of the data needs to be stored in four 32bit address locations)
Further, for 16-bit or 32-bit registers which processor length greater than 8, since the width is larger than a memory address register, which also face the problem of how to arrange a plurality of bytes.