signed vs unsigned int

Stefan Behnel stefan_ml at behnel.de
Wed Jun 2 03:01:55 EDT 2010


johnty, 02.06.2010 08:43:
> 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?

See the struct module, it supports various different C types.

Stefan




More information about the Python-list mailing list