【问题标题】:How do I convert hexadecimal string to text如何将十六进制字符串转换为文本
【发布时间】:2019-11-13 10:12:19
【问题描述】:

如何在 Python 中将十六进制字符串转换为文本?

我有一个十六进制字符串

0x3C503E3235206D4C206F662033204D2048436C207765726520616464656420746F203735206D4C206F6620302E3035204D2048436C2E20546865206D6F6C6172697479206F662048436C20696E2074686520726573756C74696E6720736F6C7574696F6E20202026656D73703B26656D73703B26656D73703B26656D73703B2020200D0A20202026656D73703B26656D73703B26656D73703B26656D73703B2020697320617070726F78696D6174656C792D P>

我想在 Python 的帮助下将其转换为文本。我该怎么做?

我试过了

print(bytes.fromhex(xyz))

xyz 是存储此字符串的变量,但出现此错误

fromhex() arg 中位置 1 处的非十六进制数

【问题讨论】:

    标签: python python-3.x string encoding base64


    【解决方案1】:

    只需从字符串的开头切出'0x' 字符。所以

    print(bytes.fromhex(var[2:]))
    

    会给

    b'<P>25 mL of 3 M HCl were added to 75 mL of 0.05 M HCl. The molarity of HCl in the resulting solution   &emsp;&emsp;&emsp;&emsp;   \r\n   &emsp;&emsp;&emsp;&emsp;  is approximately-'
    

    【讨论】:

      猜你喜欢
      • 2013-02-07
      • 1970-01-01
      • 2017-08-23
      • 2014-03-19
      • 2011-08-25
      • 2014-04-28
      • 2018-01-31
      • 2018-01-22
      相关资源
      最近更新 更多