🌀IN-DEPTH EXPLANATION🌃 | EASY-CLEAN SOLUTION✅| 💯BEATS 100⚡[PYTHON(masking)/C++/Java/JS]🍨
IntuitionWe need to add two integers without using + or -. This can be done using bitwise operations:
XOR (^) computes the sum without carry.

If we want to cal
# Intuition
We need to add two integers without using `+` or `-`. This can be done using bitwise operations:
- XOR (`^`) computes the sum without carry.
>If we want to calculate the sum of a and b such that a and b has no common set bit, then a ^ b is same as a + b. So, we can say that a + b without carry = a ^ b. 
- AND (`&`) followed by left shift (`<< 1`) computes the carry.
>To calculate the carry, we know that carry will only have the common set bits of a and b, shifted 1 place to the left. So, we can say that carry = (a & b) << 1.
- We repeat the process until there is no carry left.

>Handling negative numbers:
**In C++ and Java, integers are fixed-width (32-bit signed). Python, however, supports arbitrary precision, so we need masking to mimic 32-bit integer behavior.**

# Approach
### **Step 1: Compute Sum Without Carry Using XOR (`^`)**
- `XOR` (`^`) adds two numbers without considering the carry.
- This effectively adds bits where only one of them is `1`, while ignoring cases where both are `1` (which should generate a carry).

### **Step 2: Compute the Carry Using AND (`&`) and Left Shift (`<< 1`)**
- `AND` (`&`) identifies positions where both bits are `1`, meaning a carry is needed.
- The result is then left-shifted (`<< 1`) to move the carry to the correct position for the next iteration.

### **Step 3: Iterative Addition Until Carry Becomes Zero**
- Repeat the process while `b` (carry) is not `0`:
  1. Compute the carry: `(a & b) << 1`
  2. Compute the sum without carry: `a = a ^ b`
  3. Assign `b = carry` to process the carry in the next loop.

### **Step 4: Return the Final Result**
- When `b` becomes `0`, `a` holds the final sum, which is returned.


# Complexity
- **Time Complexity**: `O(log(max(a, b)))`
  Each iteration processes one bit, up to 32 iterations in the worst case.
- **Space Complexity**: `O(1)`

# Code
```cpp []
class Solution {
public:
    int getSum(int a, int b) {
        int x = a ^ b; 
        int y = (a & b) << 1; 
        while (y != 0) {
            int car = (x & y) << 1;
            x = x ^ y;
            y = car;
        }
        return x;
    }
};
```
```python []
class Solution:
    def getSum(self, a: int, b: int) -> int:
        MASK = 0xFFFFFFFF  # Mask to get last 32 bits
        MAX_INT = 0x7FFFFFFF  # Max positive 32-bit integer

        x = a & MASK
        y = b & MASK

        while y != 0:
            car = (x & y) << 1
            x = x ^ y
            y = car & MASK  # Ensure it remains 32-bit

        # Convert to a signed integer if the result exceeds MAX_INT
        return x if x <= MAX_INT else ~(x ^ MASK)


```
```java []
class Solution {
    public int getSum(int a, int b) {
        while (b != 0) {
            int carry = (a & b) << 1;
            a = a ^ b;
            b = carry; 
        }
        return a;
    }
}


```

```javascript []
/**
 * @param {number} a
 * @param {number} b
 * @return {number}
 */
var getSum = function(a, b) {
    while (b !== 0) {
        let carry = (a & b) << 1;
        a = a ^ b;
        b = carry;
    }
    return a;
};


```
```

✨ AN UPVOTE WILL BE APPRECIATED ^_~ ✨
```
['Math', 'Bit Manipulation', 'Python', 'C++', 'Java', 'Python3', 'JavaScript']