[Tutor] More confusion on conversion

Alan Gauld alan.gauld at blueyonder.co.uk
Thu Oct 30 18:58:25 EST 2003


> > How is this padded to two places? 0x30 is ASCII for 48?
> > Do you mean 0x20 which is a space? I will assume so...
>
> That is how it gets weird. I have to send a 0x30 which represents a
'0'.

Yes my mistake, 48 is the ASCOII code for zero.

So what you need is to send 48,65 down your port, which
are the ASCII codes for '0A'.

And you get the '0A' by using the string format operator:

value = 10
# create a 2 char, zero padded, upper case hex string
hexString = "%02X" % value

# send it to a port char at a time
for ch in hexString: sendToPort(ord(ch))

Should, I think, do what you want?

Alan G.




More information about the Tutor mailing list