leetcodedaybyday - Beats 100% with C++ -  100% with Python3 - 100% with Java
IntuitionTo solve this problem, we need to count the number of bits set (1s) at even and odd positions in the binary representation of a given integer. We can a
# Intuition
To solve this problem, we need to count the number of bits set (1s) at even and odd positions in the binary representation of a given integer. We can achieve this efficiently using bitwise operations.

# Approach
1. **Initialize Counters:**  
   - Use an array `res = [0, 0]` where `res[0]` keeps track of set bits at even positions and `res[1]` keeps track of set bits at odd positions.
   
2. **Iterate Through Bits:**  
   - Use a loop to extract and check each bit from `n` using `n & 1`.
   - If the bit is set (1), increment `res[i % 2]` depending on whether `i` (bit position) is even or odd.
   - Shift `n` right (`n >>= 1`) to process the next bit.
   - Increment the position counter `i` to track the index of the bit.

3. **Return the Result:**  
   - After processing all bits, return the `res` array containing the counts of even and odd positioned set bits.

# Complexity
- **Time Complexity:** `O log n` 
  - The loop runs at most `O log n` times since an integer \(n\) has at most `log2(n)` bits.

- **Space Complexity:** \(O(1)\)  
  - Only a fixed array of size 2 is used, making the space complexity constant.

# Code
```cpp []
class Solution {
public:
    vector<int> evenOddBit(int n) {
        vector<int> res(2, 0);
        int i = 0;
        while (n > 0){
            if (n & 1){
                res[i % 2]++;
            }
            n >>= 1;
            i++;
        }
        return res;
    }
};


```
```java []
class Solution {
    public int[] evenOddBit(int n) {
        int[] res = new int[2];
        int i = 0;
        while (n > 0){
            if ((n & 1) == 1){
                res[i % 2]++;
            }
            n >>= 1;
            i++;
        }
        return res;
    }
}


```
```python3 []
class Solution:
    def evenOddBit(self, n: int) -> List[int]:
        res = [0, 0]
        i = 0
        while n > 0:
            if n & 1:
                res[i % 2] += 1
            n >>= 1
            i += 1
        return res


```


['Bit Manipulation', 'C++', 'Java', 'Python3']