Re: Conversion from string to integer

2006-03-22 Thread Mark Warburton
Grant Edwards wrote: > On 2006-03-22, Mark Warburton <[EMAIL PROTECTED]> wrote: > > Ahh, right. Batteries included! Thanks for the enlightenment. :) > > I think that's the third time _today_ that question has been > answered. Where can we put that information such that you > would have found it

Re: Conversion from string to integer

2006-03-22 Thread Grant Edwards
On 2006-03-22, Mark Warburton <[EMAIL PROTECTED]> wrote: > Peter Otten wrote: >> To convert them you need struct.unpack() > > Ahh, right. Batteries included! Thanks for the enlightenment. :) I think that's the third time _today_ that question has been answered. Where can we put that informatio

Re: Conversion from string to integer

2006-03-22 Thread Mark Warburton
Peter Otten wrote: > To convert them you need struct.unpack() Ahh, right. Batteries included! Thanks for the enlightenment. :) -- http://mail.python.org/mailman/listinfo/python-list

Re: Conversion from string to integer

2006-03-22 Thread Mark Warburton
You want something like this: >>> a = '\x1dz' >>> (ord(a[0])<<8) + ord(a[1]) 7546 Each of the two characters represents one byte of a 16-bit integer. It doesn't matter if they are ascii or hex -- there are still exactly two bytes in each of your strings. The ord() function converts a character

Re: Conversion from string to integer

2006-03-22 Thread Terry Reedy
"xkenneth" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi, > > I've been attempting to write a serial program in python. I talk to > a custom designed bit of hardware that sends me back groups that are 2 > bytes in length. When i recieve them using either pySerial or USPP i'm

Re: Conversion from string to integer

2006-03-22 Thread Peter Otten
xkenneth wrote: > I've been attempting to write a serial program in python. I talk to > a custom designed bit of hardware that sends me back groups that are 2 > bytes in length. When i recieve them using either pySerial or USPP i'm > not sure how python interprets them. Both of the bytes should be