【问题标题】:How to convert string hex into bytes format? [duplicate]如何将字符串十六进制转换为字节格式? [复制]
【发布时间】:2022-11-29 18:31:37
【问题描述】:

字符串就像“e52c886a88b6f421a9324ea175dc281478f03003499de6162ca72ddacf4b09e0”,当我运行代码时,输​​出不是我的预期,像这样。

hexstr = "e52c886a88b6f421a9324ea175dc281478f03003499de6162ca72ddacf4b09e0"
hexstr = bytes.fromhex(hexstr)
print(hexstr)

输出是

b'\xe5,\x88j\x88\xb6\xf4!\xa92N\xa1u\xdc(\x14x\xf00\x03I\x9d\xe6\x16,\xa7-\xda\xcfK\t\xe0'

我的预期输出应该像 b'\xe5\x2c\xc8\x86 ......

【问题讨论】:

    标签: python python-3.x python-2.7 hex byte


    【解决方案1】:

    你的代码是正确的。

    Python 试图通过以下方式提供帮助显示映射到 ASCII 字符的字节作为该字符。例如,, 映射到 ,

    >>> b',' == b','
    True
    

    【讨论】:

      猜你喜欢
      • 2017-08-23
      • 2021-05-19
      • 2022-07-08
      • 2019-07-27
      • 2019-09-26
      • 1970-01-01
      • 2013-02-07
      • 1970-01-01
      • 2023-03-07
      相关资源
      最近更新 更多