[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!
print("".join("{:02x}".format(ord(c)) for c in "\016\f\016\031")) print("".join("{:02x}".format(ord(c)) for c in "\032\013\030\031\017#\004\036"))
"\032\013\030\031\017#\004\036" 和 “\016\f\016\031”是从文件里读出来的,操作的时候相当于一个字符串变量,你这样写实现不了。如果不是读出来的,可以这样:print “\016\f\016\031”.encode("hex")
import binascii print(binascii.hexlify(open('test.bin', 'rb').read()).decode('utf-8'))
import binascii print(binascii.hexlify(eval(open("test.bin", "rb").read()).encode('utf-8')).decode('utf-8'))
import binasciiprint(binascii.hexlify(eval(b"'" + open("test2.bin", "rb").read() + b"'").encode('utf-8')).decode('utf-8'))