0

我希望能够做相反的事情:

foo = long(binarystring.encode('hex'), 16)

4

3 回答 3

2
In [7]: long("1234", 16)
Out[7]: 4660L

In [8]: hex(4660L)[2:-1]
Out[8]: '1234'

[2:-1]丢弃前导和0x尾随L

于 2013-01-18T09:49:27.660 回答
2

您可以使用字符串格式,然后解码结果。

>>> binarystring = "asddfsdf"
>>> tmp = long(binarystring.encode('hex'),16)
>>> ( "%x" % tmp ).decode('hex')
'asddfsdf'
于 2013-01-18T09:51:42.113 回答
0

使用 binascii.hexlify() - 应该这样做

于 2013-01-18T09:53:02.843 回答