int divide(int a, int b) {
		if (b == 0)
			throw new ArithmeticException();

		boolean neg = (a > 0) ^ (b > 0);
		if (a < 0) {
			a = -a;
		}

		if (b < 0) {
			b = -b;
		}

		if (a < b)
			return 0;

		int msb = 0;
		for (msb = 0; msb < 32; msb++) {
			if ((b << msb) >= a) {
				break;
			}
		}

		int q = 0;
		for (int i = msb; i >= 0; i--) {
			if ((b << i) > a) {
				continue;
			}
			q |= (1 << i);
			a -= (b << i);
		}

		if (neg)
			return -q;

		return q;
	}