String to Hex
Rick Holbert
holbertr at dma.org
Wed Oct 27 15:27:27 EDT 2004
The following look like they will work on Python 2.3.4:
long(float('-0x55aff8080000'))
int(float('-0x55aff8080000'))
eval('-0x55aff8080000')
Some programmers frown upon the use of eval(), so use it at your own risk.
Comments?
Rick
Michael Foord wrote:
> How do you safely turn an arbitrarily long signed hex string into a
> long integer ?
> e.g. -0x55aff8080000
>
> When treating them as hex literals I'm getting future warnings that
> from 2.4 hex values greater than sys.maxint will always return
> positive values. I've had to treat them as strings and write a
> function to turn them into longs a character at a time ! I couldn't
> find a built in function that would do this for me.
>
> Regards,
>
> Fuzzy
>
> http://www.voidspace.org.uk/atlantibots/pythonutils.html
More information about the Python-list
mailing list