hex to signed integer
tomg at em.ca
Thu Jul 17 02:04:36 CEST 2003
My question basically is: What is the opposite of the following?
| "%08X" % -1
I want to convert a string of hexadecimal characters to the signed
integer they would have been before the <print> statement converted
them. How do I do this in such a way that is compatible with Python
versions 1.5.2 through 2.4, and not machine-dependent?
This is my current best:
| struct.unpack("!l", \
| chr(string.atoi(hexbit[0:2], 16)) + \
| chr(string.atoi(hexbit[2:4], 16)) + \
| chr(string.atoi(hexbit[4:6], 16)) + \
| chr(string.atoi(hexbit[6:8], 16)))
Thanks in advance.
Tom Goulet, tomg at em.ca, D8BAD3BC, http://web.em.ca/~tomg/contact.html
More information about the Python-list