Java easy understanding solution with detailed explanation
We can slove this problem with a similar approach as base 2, but with a small twist.\n\nWhen N is a postive number, for example N = 2, 2 / (-2) = -1, 2 % (-2) =
We can slove this problem with a similar approach as base 2, but with a small twist.\n\nWhen N is a postive number, for example N = 2, 2 / (-2) = -1, 2 % (-2) = 0, as 2 = (-2) * (-1) + 0, the remainder is either 0 or 1 which satisfy our problem. \nWhen N is a negative number, for example N = -1,  -1 / (-2) = 0,  -1 % (-2) = -1, as  -1 = (-2) * 0 + (-1), the remainder is -1 which doesn\'t satisfy our problem. We can do the following math trick to convert the negative remainder to positive.\n\n\nwe add -2 and substract -2, so the equation still remains accurate, but we convert negative remainder to postive. \n-1 = (-2) * 0 + (-1)\n-1 = (-2) * 0 **+ (-2)** + (-1) **- (-2)** \n-1 = (-2) * **(0 + 1)** + (-1) **- (-2)**\n\n\n```\npublic String baseNeg2(int N) {\n        if (N == 0) return "0";\n        StringBuilder sb = new StringBuilder();\n        while (N != 0) {\n            int r = N % (-2);\n            N = N / (-2);\n            if (r < 0) {\n                r += 2;\n                N += 1;\n            }\n            sb.append(r);\n        }\n        return sb.reverse().toString();\n    }\n\n
[]