Solution with ACTUAL explanation (how you would work this out)
Since a lot of people say they don\'t get how the solution is derived, here\'s an explanation.\n\nWhen faced with a "perform arithmetic operation without using 
Since a lot of people say they don\'t get how the solution is derived, here\'s an explanation.\n\nWhen faced with a "perform arithmetic operation without using the operator" question, the chances are you will have to use bit manipulation.\n\nThe key insight is to realize that basic mathematical rules still work when using binary. So to solve these questions you should:\n\n1. Work out how the basic mathematical operation works step-by-step\n2. Replicate these operations using the basic bitwise operators <<, >>, &, ^, |\n\nIn this case, we have addition. How does addition work normally (base 10/decimal)?\n1. If the two digits of the number add up to less than 10, you add that digit to your sum, with no carry\n2. If the two digits of the number add up to 10 or more, you add the least significant digit and carry the 1 to the next position.\n\nNow in binary, our least significant digit is always 0, so this actually makes things simpler a bit.\n\nLet\'s look at an example of adding 2 + 3:\n\n0 0 1 0 (2)\n0 0 1 1 (3)\n\nFirst, let\'s look at the rightmost bits. 0 + 1 = 1 "one" and 1 "zero", so we have 1. This gives us:\n\n0 0 1 0 (2)\n0 0 1 1 (3)\n\nNow let\'s look at the next digit (2nd from the right. 1 + 1. Here we have to carry since we have two "ones", and the maximum we can have in binary is 1, just as the maximum we can have in base 10 is 10. So just like in regular decimal addition, we set our bit here to 0 and carry the 1 to the left. This gives us our final answer:\n\n0 1 0 1 (5)\n\nNow when we look at the final solution, all we are doing is repeating these steps over and over again until we have nothing left to carry.\n\nHow do we check if only one bit is 1? Use ^.\nHow do we check if both bits are 1? Use &.\n\nThen the final step is to work out when to terminate your addition. I would argue this is actually quite tricky and pushes the question above easy. But if you wouldn\'t work it out you could actually just use a loop through all of the bits.\n\n```\npublic int getSum(int a, int b) {\n        if(a == 0) {\n            return b;\n        }\n        \n        if(b == 0) {\n            return a;\n        }\n        \n        int carry = 0;\n        \n        while(b != 0) {\n            \n            // If both bits are 1, we set the bit to the left (<<1) to 1 -- this is the carry step\n            carry = (a & b) << 1;\n            \n            // If both bits are 1, this will give us 0 (we will have a carry from the step above)\n            // If only 1 bit is 1, this will give us 1 (there is nothing to carry)\n            a = a ^ b;\n            \n            b = carry;\n        }\n        \n        return a;\n    }\n```
[]