Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我能够将十六进制数据转换为十进制:
file = open("my_text.txt", "r+") data = input("Type Hex: ") hex = int(data, 16) str(hex) print(str(hex)) file.write(str(hex)) file.close() input("close: ")
但是如何将十进制数据(如数字或句子)转换为十六进制?另外,是否可以将数据写入十六进制偏移量?
这样的事情怎么样?
>>> print(hex(257)) 0x101 >>> for ch in b'abc': ... print(hex(ch)) ... 0x61 0x62 0x63
顺便说一句,分配给一个名为“hex”的变量会遮挡内置函数——最好避免这种情况。
高温高压