[Tutor] Re: sending hex data on port

Neil Schemenauer nas-pytut@python.ca
Wed Jun 18 15:17:21 2003


vicki@stanfield.net wrote:
> Okay, sorry to reply to my own post, but I am still
> working on this. I tried something which I think is
> close to what I need. I am using binascii.
> 
> port.write(binascii.a2b_hex("18"))
> 
> Is this what I am supposed to be using to translate dec
> to hex?

I think you are confused about the difference between numbers and
strings.  The hex() builtin requires an integer as an argument.  '18' is
a string.  You really need to be more specific as to what you want to
do.  '18' could be interpreted as a number in base 10 or in base 16 or
in lots of other ways.  For example, if the value you have is '1829',
what are the characters you want to write to port?

  Neil