One problem is that (as noted) there seem to be extra "stuck bits" in the original example. Your code notes that this acts as a 13-bit 2's complement binary. 13 bits means that the "real" values that matter to us are in the range of 0 .. 8191, so a value of 12288 (representing -256) is outside this range, having bit 13 (8192) "stuck" on -- the "real" (unsigned) number is 4096, or 2^12. To get its signed value, we need to "extend the sign bit" (bit 12) -- the easiest way to do this is to test if the number is >= 4096 (i.e. has the sign bit set) and "extend" it by subtracting 2^13 (8192).
The "forward" algorithm thus is this:
![Forward Temp.png Forward Temp.png]()
Inverting this is straight-forward, except for handling the apparently "stuck" bit 13, which we can do at the very end:
![Backward Temp.png Backward Temp.png]()
The "false" cases above are just straight-through wires.
Wow, it's been a long time since I dealt with "offset-binary" and two's complement numbers.
Bob Schor