Binary to Hex conversions

Alex Martelli alex at magenta.com
Fri Aug 18 12:28:14 EDT 2000


"Pieter Claerhout" <PClaerhout at CREO.BE> wrote in message
news:2B1262E83448D211AE4B00A0C9D61B03013013F5 at msgeuro1.creo.be...
> And how can a hex number (which i have as string)
> be converted to an integer??

import string

the_integer = string.atoi(thestring, 16)


That's assuming the string is something like, say, '2a3b',
just hex digits.  If it starts with a '0x' before the hex
digits, then passing a 'base' of 0 to string.atoi is one
possibility (it means: look at the number-syntax to find
out the real base, 10, 8, or 16).


Alex






More information about the Python-list mailing list