擅长:python、mysql、java
<p>多亏了ginginsha,我才能够创建一个将字节转换为可打印字节的函数:</p>
<pre><code>def byte_pbyte(data):
# check if there are multiple bytes
if len(str(data)) > 1:
# make list all bytes given
msg = list(data)
# mark which item is being converted
s = 0
for u in msg:
# convert byte to ascii, then encode ascii to get byte number
u = str(u).encode("hex")
# make byte printable by canceling \x
u = "\\x"+u
# apply coverted byte to byte list
msg[s] = u
s = s + 1
msg = "".join(msg)
else:
msg = data
# convert byte to ascii, then encode ascii to get byte number
msg = str(msg).encode("hex")
# make byte printable by canceling \x
msg = "\\x"+msg
# return printable byte
return msg
</code></pre>