Re: trouble converting c++ bitshift to python equivalent

2007-05-24 Thread Grant Edwards
On 2007-05-24, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: >> You should really use the struct module for that type of conversion, but >> you also need to know that indexing of lists and tuples starts at 0, not 1. > > indeed, i used to have temp = unpack('h', tBuf[1,3]) Which probably should have

Re: trouble converting c++ bitshift to python equivalent

2007-05-24 Thread Grant Edwards
On 2007-05-24, Steve Holden <[EMAIL PROTECTED]> wrote: >> i have two string bytes i need to push into a single (short) int, like >> so in c: >> >>temp = strBuf[2]; >> >>temp = (temp<<7)+(strBuf[1]); > You should really use the struct module for that type of conversion, The struct modul

Re: trouble converting c++ bitshift to python equivalent

2007-05-24 Thread [EMAIL PROTECTED]
> You should really use the struct module for that type of conversion, but > you also need to know that indexing of lists and tuples starts at 0, not 1. indeed, i used to have temp = unpack('h', tBuf[1,3]) but it was a hack (and as such a bit off ;) as i was having troubles casting not quite use

Re: trouble converting c++ bitshift to python equivalent

2007-05-24 Thread [EMAIL PROTECTED]
> (ord(strBuf[2])<<7) + ord(strBuf[1]) wow, thank you - works perfectly ! and much more elegant than what i was up to. thanks again... -- http://mail.python.org/mailman/listinfo/python-list

Re: trouble converting c++ bitshift to python equivalent

2007-05-24 Thread Steve Holden
[EMAIL PROTECTED] wrote: > hello all > > i am relatively new to python, catching on, but getting stuck on > simple thing: > > i have two string bytes i need to push into a single (short) int, like > so in c: > >temp = strBuf[2]; > >temp = (temp<<7)+(strBuf[1]); > > c code works, but ha

Re: trouble converting c++ bitshift to python equivalent

2007-05-24 Thread Grant Edwards
On 2007-05-24, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > hello all > > i am relatively new to python, catching on, but getting stuck on > simple thing: > > i have two string bytes i need to push into a single (short) int, like > so in c: > >temp = strBuf[2]; > >temp = (temp<<7)+(strBuf

trouble converting c++ bitshift to python equivalent

2007-05-24 Thread [EMAIL PROTECTED]
hello all i am relatively new to python, catching on, but getting stuck on simple thing: i have two string bytes i need to push into a single (short) int, like so in c: temp = strBuf[2]; temp = (temp<<7)+(strBuf[1]); c code works, but having trouble getting python to perform same functio