def twosComplementToSignedInteger(twosComplement, bitSize):
    """Converts a twos-complement representation into a signed integer.
     
    twos-complement -- the number to be converted.
    bitSize -- the length in bits of the two's complement input.
    """
           
    signBitPosition = bitSize - 1    #sign bit is the most significant bit
    signBit = 2**signBitPosition    #a single bit in the MSB position
    if(signBit & twosComplement):   #number is negative, need to take two's complement
        allOnes = 2**bitSize - 1 # fills size bytes with all ones
        return -((twosComplement - 1)^allOnes)   #subtract one then flip bits, the is the inverse of encoding process.
    else:
        return twosComplement