一、將P進制數x a1a2a3...an 轉換爲十進制數yspa
int y=0,product=1; while(x!=0){ y=y+(x%10)*product; x=x/10; product=product*P; }
二、將十進制數y轉換爲Q進制數z(do-while是爲了防止y=0時while循環直接跳出)code
int z[40],num=0; do{ z[num++]=y%Q; y=y/Q; }while(y!=0);
z[num-1]到z[0]即爲Q進制zblog