【问题标题】:How to convert str to hex via python [duplicate]如何通过python将字符串转换为十六进制[重复]
【发布时间】:2016-03-28 23:55:45
【问题描述】:

我想将字符串转换为十六进制(十进制), 例如abc616263 等等。 我该怎么做?

我试过了:

x= input("Enter string")
x = int(x)
hex(x)

但它不起作用。

【问题讨论】:

  • 嗯,是的,你没有将hex 的结果分配给任何东西。
  • 什么是“十六进制(十进制)”? “abc”和616263有什么关系?
  • @khelwood 正如我所想,这是abc的十六进制值的ASCII

标签: python


【解决方案1】:

也许你正在寻找类似的东西:

x.encode("hex")

【讨论】:

  • 有问题:/ LookupError: 'hex' is not a text encoding;使用 codecs.encode() 处理任意编解码器
  • 你可以试试from codecs import encode, decode encode(x, "hex")
猜你喜欢
  • 2011-05-15
  • 2018-07-03
  • 2013-02-07
  • 1970-01-01
  • 1970-01-01
  • 2019-01-17
  • 1970-01-01
  • 1970-01-01
  • 2023-03-08
相关资源
最近更新 更多