hex oct int string coversions?

R

Ron Adam

How do I covert a string hex or oct value to the correct int value?
'0764'
500
764
'0x1f4'
500
Traceback (most recent call last):
File "<pyshell#65>", line 1, in ?
int(t)
ValueError: invalid literal for int(): 0x1f4
 
R

Ron Adam




That tells me how to convert an int to a hex or oct string using the
hex() and oct() functions, which I already know.

The int() function will convert a string to an integer. But it
doesn't understand hex or oct from a string., You can type the hex,
or oct value as an argument for the int() function on the command line
and that works correctly.

So there must be a way to do it? Am I missing a step?

_Ron
 
R

Ron Adam

That tells me how to convert an int to a hex or oct string using the
hex() and oct() functions, which I already know.

The int() function will convert a string to an integer. But it
doesn't understand hex or oct from a string., You can type the hex,
or oct value as an argument for the int() function on the command line
and that works correctly.

So there must be a way to do it? Am I missing a step?

_Ron


It was there, I wasn't looking at it correctly. int(s,0) or
int(s,8) works great. Thanks Martin. And also to Mike who pointed
it out to me in email.

I really need to get more sleep.

_Ron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top