s = "317"
#s = s.encode("utf8")
s = hex(int(s))
print(s)
s = int(s, 16)
str2 = struct.pack('>i', s)
#print(s, len(s))
print(str2)

python 使用struct.pack 转16进制_数据