[Tutor] More confusion on conversion

Reggie Dugard reggie at merfinllc.com
Thu Oct 30 15:46:39 EST 2003


Vicki,

Forgive me if I'm being dense, but how many bytes do you want to write
out on the port for each length?  If the answer is 2, then writing '0'
and 'A' is equivalent to writing 0 and 65 which is equivalent to writing
0x00 and 0x41 - they all have the same bit pattern: 00000000 01000001.

Sorry if I'm misunderstanding you.

Reggie

On Thu, 2003-10-30 at 12:24, Stanfield, Vicki {D167~Indianapolis} wrote:
> Nope, this write '0A' out one the port. I need to write the hex value of the 0 and then the hex value of the 'A'. WHen I tried this:
> 
> for each in [ hex(ord(x)) for x in '%02X' % length ]:
>                     port.write('%02X' %each)
>                     time.sleep(.01)
>                     print '%02X' %each
> 
> It was close, but it wants an integer instead of the hex values.
> 
> port.write('%02X' %each)
> TypeError: an integer is required
> 
> --vicki
> 
> -----Original Message-----
> From: Reggie Dugard [mailto:reggie at merfinllc.com]
> Sent: Thursday, October 30, 2003 3:09 PM
> To: Stanfield, Vicki {D167~Indianapolis}
> Cc: tutor at python.org
> Subject: RE: [Tutor] More confusion on conversion
> 
> 
> Vicki,
> 
> If I understand you correctly you simply want something like:
> 
> 	port.write('%02X' % length)
> 
> This should write 2 bytes on the port, one for each hex digit.  If I'm
> misunderstanding what you want, maybe you can clarify it a bit more.
> 
> Also, I'm sending this back to the list so that people more
> knowledgeable than me can help you out as well.
> 
> Good luck with your problem.
> 
> Reggie






More information about the Tutor mailing list