参考网址:
https://docs.python.org/3/library/struct.html
https://blog.csdn.net/wowocpp/article/details/79485868
https://blog.csdn.net/wowocpp/article/details/79487091
参考书籍:
Python标准库.[美]Doug Hellmann(详细书签).pdf
中文: 第二章 第6节
struct.pack('>BBHH', host, fc, 0, max_addr)
测试程序:
import array
import sys
import struct
# 80 04 01 00 00 10 ee 2b
data = b'\x80\x04\x01\x00\x00\x10\xee\x2b'
aa = data.encode('hex')
print aa
print aa.decode('hex')
print len(data)
bb = struct.unpack('BBBBBBBB', data)
print 'bb = ', bb
for dd in bb :
print dd
print type(dd)
a = 0x80
b = 0x04
c = struct.pack('ii',0x80,0x04)
print c
log:
800401000010ee2b
� �+
8
bb = (128, 4, 1, 0, 0, 16, 238, 43)
128
<type 'int'>
4
<type 'int'>
1
<type 'int'>
0
<type 'int'>
0
<type 'int'>
16
<type 'int'>
238
<type 'int'>
43
<type 'int'>
�
注意 :python 中 char 和byte 的区别
(稍后补充)