@@ -0,0 +1,1033 @@
+/**%0A * Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.%0A * %3Cp%3E%0A * Example:%0A * Given a = 1 and b = 2, return 3.%0A * %3Cp%3E%0A * Tags: Bit Manipulation%0A * Similar Problems: (M) Add Two Numbers%0A */%0Apublic class SumOfTwoIntegers %7B%0A%0A    /**%0A     * For example, a = 0001, b = 0011.%0A     * First, we can use %22and%22(%22&%22) operation between a and b to find a carry.%0A     * carry = a & b, then carry = 0001%0A     * Second, we can use %22xor%22 (%22%5E%22) operation between a and b to find the different bit, and assign it to a.%0A     * Then, we shift carry one position left and assign it to b, b = 0010.%0A     * Iterate until there is no carry (or b == 0)%0A     */%0A    public int getSum(int a, int b) %7B%0A        if (b == 0) return a;%0A%0A        while (b != 0) %7B%0A            int carry = a & b;%0A            a = a %5E b;%0A            b = carry %3C%3C 1;%0A        %7D%0A%0A        return a;%0A    %7D%0A%0A    public int getSumRecursive(int a, int b) %7B%0A        if (b == 0) return a;%0A        return getSumRecursive(a %5E b, (a & b) %3C%3C 1);%0A    %7D%0A%0A%7D%0A

add Sum Of Two Integers