Files
clearn/xto10.c
2017-02-07 20:03:49 +00:00

42 lines
847 B
C

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
unsigned long base10;
int oldbase;
char c[100];
unsigned long rest,erg;
int pos=0;
int i;
int main()
{
base10=0;
oldbase=36;
for(i=0;i<100;c[i++]=0);
printf("Altes Zahlensystem:");
scanf("%d",&oldbase);
printf("Zahl im %der-System:",oldbase);
scanf("%s",&c);
pos=0;
while(c[pos++]);
pos--;
int len=pos-1;
while(pos--)
{
if(isdigit(c[len-pos]))
{
base10 = base10 + (unsigned long)( (double)(c[len-pos]-'0') * ( pow( (double)oldbase,(double)pos ) ) ) ;
printf("-N-DEBUG: base10:%d, c:%c, pos:%d\n",base10,c[pos],pos);
}
else
{
base10 = base10 + (unsigned long)( ((double)(c[len-pos]-'A')+10) * ( pow( (double)oldbase,(double)pos ) ) );
printf("-A-DEBUG: base10:%d, c:%c, pos:%d\n",base10,c[pos],pos);
}
}
printf("Zahl im 10er-system:%d\n",base10);
}