C++ Geeks4Geeks
See this Geeks4Geeks article: Convert a number into negative base representation.\n\nBelow is the specialized solution for the -2 base.\n\nstring baseNeg2(int N
See this Geeks4Geeks article: [Convert a number into negative base representation](https://www.geeksforgeeks.org/convert-number-negative-base-representation/).\n\nBelow is the specialized solution for the ```-2``` base.\n```\nstring baseNeg2(int N, string res = "") {\n  while (N != 0) {\n    int rem = N % -2;\n    N /= -2;\n    if (rem < 0) rem += 2, N += 1;\n    res = to_string(rem) + res;\n  }\n  return max(string("0"), res);\n}\n```
[]