c++&python
close to negetive infinity instead of close to zero, both when you calc a bit of result and when you reduce n.\n\nnotice1:  \noperator % in python2/python3 is m
close to negetive infinity instead of close to zero, both when you calc a bit of result and when you reduce n.\n\nnotice1:  \noperator % in python2/python3 is mod operator(close to negetive infinity). for example, 7%-2=7-4*(-2)=-1\noperator % in c/c++/java,etc. is reminder operator(close to zero). for example, 7%-2=7-3*(-2)=1\n\nnotice2:  \nint(n/2) in python2 is close to negetive infinity. for example, int(7/-2)=-4\nint(n/2) in python3/c/c++/java,etc. is close to zero. for example, int(7/-2)=-3\n\nwe can implement close-to-negetive-infinity division via `n>>1` (for n/2) , and implement mod operator via `n-(n>>1)*(-2)`\n\n\nc++:\n\n```c++\nclass Solution {\npublic:\n    string baseNeg2(int n) {\n        if(n==0) return "0";\n        string result;\n        while(n) {\n            int c=n>>1;\n            result += to_string(n-2*c);\n            n = -c;\n        }\n        reverse(result.begin(), result.end());\n        return result;\n    }\n};\n```\n\npython:\n```python\nclass Solution(object):\n    def baseNeg2(self, n):\n        if n==0:\n            return "0"\n        result = ""\n        while n!=0:\n            result = str(n%2) + result\n            n = -(n / 2);\n        return result\n```\n\npython3:\n```python3\nclass Solution:\n    def baseNeg2(self, n: int) -> str:\n        if n==0:\n            return "0"\n        result = ""\n        while n!=0:\n            result = str(n%2) + result\n            n = -int(n>>1);\n        return result\n```
[]