C++ | Easy solution with detailed explanation
Approach: \n1. Everything will be same as we convert decimal to binary with base 2. \n2. Taking base as -2. Find remainer using N%(-2) and divide no with (-2) a
Approach: \n1. Everything will be same as we convert decimal to binary with base 2. \n2. Taking base as -2. Find remainer using N%(-2) and divide no with (-2) after each iteration. \n3. We just have to handle the case when remainder is negative. `r = r + abs(-2)` and `N = N /(-2) +1` ; \n\nExample : \nN = -5 and base -2. Negative remainder will only occur when n is negative. \n```\n\nN = (divisor) * (quoteint) + remiander \n-5 = (-2 )* (2) + -1\n```\nTo make remainder positive and within the range we can add and subtract base value. \n```\n-5 = (-2)* 2 + (-2) + -1 + 2\n-5 = (-2) * (2 + 1) + (-1+2 ) \n-5 = (-2) * (3) +1 \n```\n\nNow remiander is positive and within range (0 - 1) and quotient will be N/(-2) + 1 \n\n\n\n```\n   string baseNeg2(int n) {\n        string ans="";\n        if(n==0)\n            ans+=(\'0\');\n        int r;\n        while(n){\n            r=n%(-2);\n            if(r<0){\n                r+=2;\n                n=n/(-2)+1;\n            }else\n                n/=(-2);\n            ans+=(r+\'0\');\n        }\n        reverse(ans.begin(),ans.end());\n        return ans;\n    }\n```
['C', 'C++']