[Tutor] More confusion on conversion

Lloyd Kvam pythontutor at venix.com
Thu Oct 30 16:18:23 EST 2003


length = 10
for each in [ hex(ord(x)) for x in '%02X' % length ]:
     port.write( each[2:])	# don't sent the leading 0x
     time.sleep(.01)
     print each

I would expect this to work based upon your first email.


Reggie Dugard wrote:

> 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
> 
> 
> 
> 
> 
> _______________________________________________
> 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