簡體   English   中英

如何將 python 二進制字符串轉換為十六進制?

[英]How can I convert a python binary string to hex?

binary_str = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'

如何在 python 中將此二進制數據轉換為十六進制數據?

我試過這樣,但它不工作。

>>> hex(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'bytes' object cannot be interpreted as an integer

在 python 中, hex不能這樣工作。 試試這樣:

binary_str = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'

print(binary_str.hex())

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM