I have integer num
, which can be negative or positive and also I have number P (1 < P <= 9).
What I want to do is to convert num to base-P.
I easily do it when num > 0
:
int i = 0;
int A[10000];
while (num != 0)
{
A[i] = num % p;
num /= p;
i++;
}
But I don't know how to achieve it when num < 0
.