1ms runtime with explanation
For converting to base 2, we can use the double dabble method.\n\n\nIntuition:\nUsing the double dabble method, we can obtain exactly half the bits right for ba
For converting to base 2, we can use the double dabble method.\n![Circuit globe](https://circuitglobe.com/wp-content/uploads/2016/09/decimal-to-binary-conversion-example-1.jpg "Double Dabble method to convert integer to binary")\n\n**Intuition:**\nUsing the double dabble method, we can obtain exactly half the bits right for base -2 representation. It must mean we have to adjust the rule for calculating odd-powered bits. After some trial and error, I could obtain the correct base -2 representation by performing double dabble for base 2, except now while dividing the number at every alternate step, I ceiled the integer instead of flooring.\n\n\n| Divisor | Dividend | Remainder |\n| --- | --- | --- |\n| 2 | 7 | 1 |\n| 2 | 3 (floor 7/2 ) | 1| \n| 2 | 2 (ceil 3/2 ) | 0|\n| 2 | 1 (floor 2/2) | 1|\n| 2 | 1 (ceil 1/2 ) | 1|\n| 2 | 0 (floor 1/2 )| 0|\n\n```\nclass Solution {\n    public String baseNeg2(int N) {\n        if(N == 0) return "0";\n        String bin = "";\n        int count = 0;\n        while(N != 0){\n            bin = (N % 2) + bin;\n            if(count % 2 == 0)\n                N = (int) Math.floor(N / 2.0);\n            else N = (int) Math.ceil(N / 2.0);\n            count++;\n        }\n        return bin;\n    }\n}\n```
['Java']