I would like to convert a list of characters (represented on a single byte ie. the range [0, 255]) to be represented with integers in the range [-128,127]. I've read that Python's modulo operator (%
) always return a number having the same sign as the denominator.
What is the right way to do this conversion in Python?
EDIT
Characters that map to [128,255] with ord
should be remapped to [-128,-1], with 128 mapped to -128 and 255 mapped to -1. (For the inverse of the conversion I use chr(my_int%256)
, but my_int
can be a negative number.)