public int divide(int dividend, int divisor) {

        if (divisor == 0)
            throw new ArithmeticException("devide by zero");

        // convert dividend and divisor to negative numbers a and b
        int a = (dividend < 0) ? dividend : (0 - dividend);
        int b = (divisor < 0) ? divisor : (0 - divisor);

        // check the sign of the output
        return (dividend ^ divisor) < 0 ? (0 - divideHelper(a, b))
                : divideHelper(a, b);
    }