if you had a hex string like '0x7c' how would you convert it to an int? int(0x7c) works, but not int('0x7c')
"Patrick Stinson" <listuser@br.logorrhea.com> wrote in message news:200406161313.34568.listuser@br.logorrhea.com...
if you had a hex string like '0x7c' how would you convert it to an int?
int(0x7c) works, but not int('0x7c')
Usage questions like this belong on comp.lang.python or the corresponding mailing list, not on the development list. In addition, you should give a subject heading, something like 'Int from hex string'. '(no subject)' makes your posting look like possible spam, and it invites people who pick and choose threads to skip on to the next. Terry J. Reedy
[Patrick Stinson]
if you had a hex string like '0x7c' how would you convert it to an int?
int(0x7c) works, but not int('0x7c')
Please address questions about Python usage to comp.lang.python, or mail to help@python.org. They're off-topic on python-dev. In this case, reading the docs for int() will answer the question (honest <wink>).
Patrick,
if you had a hex string like '0x7c' how would you convert it to an int?
int(0x7c) works, but not int('0x7c')
The general python mailing list is a more appropriate place for this question. That being said, what you are looking for is int('0x7c',16). FYI int('7c',16) also works. This can be found in the Python manual (that came with Python) in the Python Library Reference section 2.1 Built in functions. You may want to scan through the tutorial and the library reference material as they both are good places to look to answer questions like this. Regards, Dan Gass
participants (5)
-
Brett Cannon -
Dan Gass -
Patrick Stinson -
Terry Reedy -
Tim Peters