hex to signed integer

Tom Goulet tomg at em.ca
Thu Jul 17 12:48:55 EDT 2003


Tim Roberts wrote:
> Tom Goulet <tomg at em.ca> wrote:
 
>>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?

>   if hexbit[0] < '8':
>     temp = int(hexbit,16)
>   else:
>     temp = int(long(hexbit,16)-2**32)

The <int> function takes only one argument in Python 1.5.2.

-- 
Tom Goulet, tomg at em.ca, D8BAD3BC, http://web.em.ca/~tomg/contact.html




More information about the Python-list mailing list