[Tutor] More confusion on conversion

Lloyd Kvam pythontutor at venix.com
Fri Oct 31 10:44:07 EST 2003


Now that you've got working code, I thought I'd add a brief summary.  Please
correct as necessary.

One of the common email encodings is base64 where the message is mapped 6 bits
at a time into printable (8 bit) characters.  This device requires an equivalent
process that maps 4 bits at a time using digits and A-F, the normal uppercase hex
characters.

One extra issue was the need to introduce a delay between each character.

Having done a lot of serial port processing years ago, I have been interested
in following this problem and am glad that you have solved it.

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
> 

-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice:	603-653-8139
fax:	801-459-9582




More information about the Tutor mailing list