code: def val_to_signed_integer(value, bitwidth):
      
      if isinstance(value, WireVector) or isinstance(bitwidth, WireVector):
          raise PyrtlError('inputs must not be wirevectors')
      if bitwidth < 1:
          raise PyrtlError('bitwidth must be a positive integer')
  
      neg_mask = 1 << (bitwidth - 1)
      neg_part = value & neg_mask
  
      pos_mask = neg_mask - 1
      pos_part = value & pos_mask
  
      return pos_part - neg_part
docs: Return value as intrepreted as a signed integer under twos complement.
  
      :param value: a python integer holding the value to convert
      :param bitwidth: the length of the integer in bits to assume for conversion
  
      Given an unsigned integer (not a wirevector!) covert that to a signed
      integer.  This is useful for printing and interpreting values which are
      negative numbers in twos complement. ::
  
          val_to_signed_integer(0xff, 8) == -1