I encoded and decoded a bunch of coefficients (related to my previous question). The process is based on RLE where a bunch of coefficients are encoded and the runtime encoding is only focused on zeros. To cut it short this was the original array:
[200, -145, 0, 0, 0, 0, 51, 0, 0, 0, 0, 0, 0, 0, 0, -34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Encoded into binary data that looks like this:
['000011001000', '11001>101101111<', '000010001110110011', '00010000111>1011110<', '00011000110011101', '000100011']
To avoid binary numbers that look like -10010001 (-145), I manually performed twos complement(since I couldn't find a built in way) on negative numbers. The results for the numbers in this case (-145, -34) were (101101111, 1011110). To avoid confusion, I marked them in the array above for the purpouse of this question.
This was padded to be divisible by 8(the last element had 0's inserted into the beginning), divided into bytes and written into a file.
When I read the file, I decoded most things successfully and the number of coefficients is identical to the starting one. The problem arose with the negative values:
[200, 367, 0, 0, 0, 0, 51, 0, 0, 0, 0, 0, 0, 0, 0, 94, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Instead of -145 i got 367 and instead of -34 i got 94.
Is there any built-in way (or any kind of way) to convert bitstrings into signed values? I feel like this would fix my issue. I haven't been able to find a way and I'm stuck now.