programming g-adic expansion in c++
<p>I want to program the g-adic expansion in the c++ language, but whatever I try, the output is still wrong. Let me first explain what the g-adic expansion is. The g-adic expansion is a way to represent numbers. For example, binary numbers, this is the 2-adic expansion of numbers. And hexadecimal is 16-adic expansion. So here is my code:</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;cmath&gt;
#include &lt;complex&gt;
#include &lt;valarray&gt;

using namespace std;

int main()
{
    int x;
    int g;
    cin&gt;&gt;x;
    cin&gt;&gt;g;
    int k=log(x)/log(g)+1;
    int e;
    int b=0;
    int* myArray=NULL;
    myArray=new int[k];

    for(int i=0;i&lt;k;i++)
    {
        myArray[i]=0;
    }

    while(b!=k)
    {
        e=x/(g^(k-b-1));
        myArray[b]=e;
        x=x-e*g^(k-b-1);
        b++;
    }

    b=0;

    while(b!=k)
    {
        cout&lt;&lt;myArray[b]&lt;&lt;endl;
        b++;
    }

    delete [] myArray;
    myArray=NULL;

    return 0;
}
</code></pre>

<p>So for example if I want to convert 105 to binary, x=105 and g=2, k is the length of the new number. In this case that is 7. int e=105/2^(7-1)=1. This is the first number. Then x=105-1*2^(7-1)=41. If you do this by hand, you will find that 105 becomes 1101001. But if I compile this piece of code, it just doesn't work. My question is what is wrong with this code?</p>
