用法:
binascii.b2a_hex(data[, sep[, bytes_per_sep=1]])
binascii.hexlify(data[, sep[, bytes_per_sep=1]])
返回二進製
data
的十六進製表示。data
的每個字節都轉換為相應的 2 位十六進製表示。因此,返回的字節對象是data
長度的兩倍。使用
bytes.hex()
方法也可以方便地訪問類似的函數(但返回文本字符串)。如果指定了
sep
,則它必須是單個字符 str 或 bytes 對象。它將在每個bytes_per_sep
輸入字節之後插入到輸出中。默認情況下,分隔符放置從輸出的右端開始計數,如果您希望從左側開始計數,請提供負的bytes_per_sep
值。>>> import binascii >>> binascii.b2a_hex(b'\xb9\x01\xef') b'b901ef' >>> binascii.hexlify(b'\xb9\x01\xef', '-') b'b9-01-ef' >>> binascii.b2a_hex(b'\xb9\x01\xef', b'_', 2) b'b9_01ef' >>> binascii.b2a_hex(b'\xb9\x01\xef', b' ', -2) b'b901 ef'
在 3.8 版中更改:
sep
和bytes_per_sep
添加了參數。
相關用法
- Python binascii.crc32用法及代碼示例
- Python binary轉string用法及代碼示例
- Python binary轉ASCII用法及代碼示例
- Python bin用法及代碼示例
- Python bin()用法及代碼示例
- Python bytes.isupper用法及代碼示例
- Python base64.b64decode()用法及代碼示例
- Python bokeh.plotting.figure.asterisk()用法及代碼示例
- Python bytes.zfill用法及代碼示例
- Python base64.b32decode()用法及代碼示例
- Python bytearray()用法及代碼示例
- Python bokeh.plotting.figure.annular_wedge()用法及代碼示例
- Python bool()用法及代碼示例
- Python bytes.isalpha用法及代碼示例
- Python base64.b85encode()用法及代碼示例
- Python bokeh.plotting.figure.circle()用法及代碼示例
- Python bytes.hex用法及代碼示例
- Python bz2.decompress(s)用法及代碼示例
- Python bokeh.plotting.figure.circle_cross()用法及代碼示例
- Python bokeh.plotting.figure.bezier()用法及代碼示例
注:本文由純淨天空篩選整理自python.org大神的英文原創作品 binascii.b2a_hex。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。