Same as Base 2 conversion🤩 | BEATS 100%⭐ | C++ 😎
🤩🤩PLEASE UPVOTE🤩🤩Approach🤍✨Approach is same as the conversion of number into base 2
There is only one change in code.......Steps🤍✨
Handle base case if(n==0) tha
***🤩🤩PLEASE UPVOTE🤩🤩***


# Approach🤍✨
Approach is same as the conversion of number into base 2
There is only one change in code.......

# Steps🤍✨
1. Handle base case `if(n==0) than answer="0")`
2. Get last bit of number --> `n = (n&1)`
3. Shift number(Just add minus) --> `n = -(n>>1)`

# Complexity🤍✨
- Time complexity: O(log(n))
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: O(log(n))

# Code for Base -2🤍✨
```cpp []
class Solution {
public:
    string baseNeg2(int n) {
        if(n==0) return "0";
        string s="";
        while(n){
            s=to_string(n&1)+s;
            n=-(n>>1);
        }
        return s;
    }
};
```
# Code for Base 2🤍✨
```cpp []
class Solution {
public:
    string baseNeg2(int n) {
        if(n==0) return "0";
        string s="";
        while(n){
            s=to_string(n&1)+s;
            n=(n>>1);
        }
        return s;
    }
};
```
***🤩🤩PLEASE UPVOTE🤩🤩***

['C++']