[Tutor] Covert numbers to hex fails
Alan G
alan.gauld at freenet.co.uk
Wed May 25 09:22:20 CEST 2005
> Good evening! I am trying to pass a number variable and have it
> converted to hex. Any recommendations on how to achieve this?
You appear to have answered your own question below.
What exactly is the problem?
FAILS
----------
>>> value = 1234567890
>>> hexoutput = hex('%d' % (value))
WORKS
-------------
>>> hexoutput = hex(1234567890)
Are you trying to insert a hex representation of the number into a
string for printing? If so the easiest way is using string format
characters:
>>> print "In hex: %d = %X" % (42,42)
In hex: 42 = 2A
HTH,
Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list