# 如何将一个巨大的数字从 x 基编号系统转换为 y 基编号系统？

##### 问题描述投票：0回答：1

#include <stdio.h>
#include <stdlib.h>
#define LEN 1000

int exp(int expBase, int power){
unsigned int i=1;
int j;
for(j=0; j<power; j++) i*=expBase;
return i;
}

void convert(char* num, int base1, int base2, int length){
char numC[LEN];
int i;
}

int getNum(char *num){
int i=0;
char c;
while((c=fgetc(stdin)) != ' '){
num[i]=c;
i++;
}
return i;
}

int main(){
char num[LEN];
int n, base1, base2, length;
scanf("%d", &n);
for(int i=0; i<n;i++){
length=getNum(num);
scanf("%d %d", &base1, &base2);
convert(num, base1, base2, length);
}
return 0;
}

arrays c numbers
##### 1个回答
0

void touint8(char* num, uint8_t *numu8, int length) {
for(int i=0 ; i<length; i++) {
if (num[i] > 0x39) {
numu8[length - i] = num[i] - 0x41;
} else {
numu8[length - i] = num[i] - 0x30;
}
}
}

void fromuint8(uint8_t *numu8, char* num, int length) {
// Inverse of touint8.
}

void idivide(uint8_t *numu8, int *length, int base1, int divisor) {
// Perform integer long division of numu8 by divisor ...
// Overwrite numu8 with result.
}

_Bool allzeroes(uint8_t *numu8, int length) {
for(int i=0 ; i<length; i++) {
if (numu8[i]) return false;
}
return true;
}

int getlsigdigit(uint8_t *numu8, int length, int base1, int base2) {
int numbase2 = 0;
int x=1;
for(int i=0 ; i<length; i++) {
numbase2 = (numbase2 + numu8[i] * x) % base2;
x = (x*base1) % base2;
}
}

char* convert(char* num, int base1, int base2, int length) {
uint8_t *numu8 = malloc(length);
uint8_t *resu8 = malloc(LEN);
touint8(num, numu8, length);
int resdigit = 0;
while(!allzeroes(numu8, length)) {
resu8[resdigit] = getlsigdigit(numu8, length, base1, base2);
idivide(numu8, &length, base1, base2);
resdigit++;
}
char *res = malloc(reslen+1);
fromuint8(resu8, res, reslen);
free(numu8);
free(resu8);
return res;
}