def twosComp ( intVal, numBits ):
  """

  This function will compute the two's compliment for the given unsigned integer
  value and bit length.

  Parameters
  ----------
  intVal:
    An unsigned integer value     
  numBits:
    Bit length of the input integer (register) 

  Returns
  -------
  signedIntVal:
    Signed two's compliment integer

  """
  signedIntVal = intVal
  if ( signedIntVal & ( 1 << ( numBits - 1 ) ) ) != 0:
    signedIntVal = signedIntVal - ( 1 << numBits )
  return signedIntVal