[Tutor] Covert numbers to hex fails
Tom Tucker
tktucker at gmail.com
Wed May 25 16:04:55 CEST 2005
Alan,
Thanks! Your response was helpful. I was trying to pass a number
variable to the hex object. The output associated with this would be
referenced in the hexoutput variable.
I guess this is as simple as....
hexoutput = "%X" % (value)
Thanks again for the help,
Tom
On 5/25/05, Alan G <alan.gauld at freenet.co.uk> wrote:
>
> > 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