def sext(binary, bits):
    """ 
    Sign-extend the binary number, check the most significant
    bit 
    """
    neg = binary & 1 << bits - 1
    if neg:
        mask = 0
        for i in range(bits, 16):
            mask |= 1 << i
        return mask | binary
    else:
        return binary
