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
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
> 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
> (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
[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
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
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