Converting a hex string to a number

Gerhard Häring gerhard.haering at gmx.de
Tue Jul 9 09:13:09 EDT 2002


* Simon.Foster at smiths-aerospace.com <Simon.Foster at smiths-aerospace.com> [2002-07-09 13:43 +0100]:
> 
> Tal said:
> 
> >Hello,
> > I am trying to convert a hex string (for example: "0x12345678") to a
> >number (0x12345678 or just 12345678).
> > Can you help me please?
> >Thanks, Tal.
> 
> eval!
> 
> C:\WINNT\Profiles\syf\Desktop>python
> Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> string = '0x12345678'

string = 'os.unlink(r"c:\boot.ini")'

> >>> eval( string )
> 305419896
> >>>

Gerhard
-- 
mail:   gerhard <at> bigfoot <dot> de       registered Linux user #64239
web:    http://www.cs.fhm.edu/~ifw00065/    OpenPGP public key id AD24C930
public key fingerprint: 3FCC 8700 3012 0A9E B0C9  3667 814B 9CAA AD24 C930
reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b')))





More information about the Python-list mailing list