def getTwosComplement(raw_val, length):
        """Get two's complement of `raw_val`.

        Args:
            raw_val (int): Raw value
            length (int): Max bit length

        Returns:
            int: Two's complement
        """
        val = raw_val
        if raw_val & (1 << (length - 1)):
            val = raw_val - (1 << length)
        return val