[Tutor] More confusion on conversion

Reggie Dugard reggie at merfinllc.com
Thu Oct 30 13:35:10 EST 2003


Ok I won't ask :-).  How about something like:

>>> length = 10
>>> [ hex(ord(x)) for x in '%02X' % length ]
['0x30', '0x41']
>>>

Reggie

On Thu, 2003-10-30 at 10:19, Vicki Stanfield wrote:
> Okay, don't ask me why because the answer I got was "for historical
> reasons", but I have to take the length of something (a decimal value) and
> convert it to its hexadecimal equivalent and then convert that value to
> its hexadecimal equivalent padded to 2 places. The result is something
> like this:
> 
> length = 10
> convert 10 to A
> convert A to 0x41
> padded version = 0x30 0x41
> 
> When I try to convert the decimal 10 using either binascii.hexlify, I am
> told that it wants a single value instead of the two digit 10. How does
> one convert a 10 (decimal value) to its hex equivalent? I don't want the
> hex equivalent of 1 followed by the hex equivalent of 0. The example above
> is exactly what I must achieve.
> 
> --vicki
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor





More information about the Tutor mailing list