convert ascii character to signed 8-bit integer python
Subtract 256 if over 127:
unsigned = ord(character)
signed = unsigned - 256 if unsigned > 127 else unsigned
Alternatively, repack the byte with the struct
module:
from struct import pack, unpack
signed = unpack('B', pack('b', unsigned))[0]
or directly from the character:
signed = unpack('B', character)[0]