code: def to_twos_comp(val, bits):
      
      if not val.startswith('-'):
          return to_int(val)
      value = _invert(to_bin_str_from_int_string(bits, bin(to_int(val[1:]))))
      return int(value, 2) + 1
docs: compute the 2's compliment of int value val