signed vs unsigned int

2010-06-02 Thread johnty
i'm reading bytes from a serial port, and storing it into an array.

each byte represents a signed 8-bit int.

currently, the code i'm looking at converts them to an unsigned int by
doing ord(array[i]). however, what i'd like is to get the _signed_
integer value. whats the easiest way to do this?

thanks in advance.

johnty
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: signed vs unsigned int

2010-06-02 Thread johnty
On Jun 2, 12:04 am, Christian Heimes li...@cheimes.de wrote:
  i'm reading bytes from a serial port, and storing it into an array.

  each byte represents a signed 8-bit int.

  currently, the code i'm looking at converts them to an unsigned int by
  doing ord(array[i]). however, what i'd like is to get the _signed_
  integer value. whats the easiest way to do this?

 http://docs.python.org/library/struct.html

the struct docs is exactly what i needed to read. unpacking it as a
signed char did the trick. thanks guys!
-- 
http://mail.python.org/mailman/listinfo/python-list