signed vs unsigned int

John Machin sjmachin at lexicon.net
Wed Jun 2 07:25:49 EDT 2010


On Jun 2, 4:43 pm, johnty <johntyw... at gmail.com> 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?

signed = unsigned if unsigned <= 127 else unsigned - 256



More information about the Python-list mailing list