code: def rev_twos_comp_repr(val, bitwidth):
      
      valbl = val.bit_length()
      if bitwidth < val.bit_length() or val == 2**(bitwidth-1):
          raise pyrtl.PyrtlError("please choose a larger target bitwidth")
      if bitwidth == valbl:  # MSB is a 1, value is negative
          return -((~val & (2**bitwidth-1)) + 1)  # flip the bits, add one, and make negative
      else:
          return val
docs: Takes a two's-complement represented value and
      converts it to a signed integer based on the provided bitwidth.
      For use with Simulation.inspect() etc. when expecting negative numbers,
      which it does not recognize