i would like to create a program that converts a number system to another
i found few ideas on how to do this but lacks explanation so i can't figure out 'how it worked'.
found that 'for loop' over the net,did some editing then applied it in a program.
here's a code
#include <iostream.h>
#include <math.h>
int main()
{
int bin,n,r,x;
char a;//looping
do
{
int s=0;
system("cls");
cout<<"Number System Conversion Program"<<endl;
cout<<"\nEnter binary: ";
cin>>bin;
n=bin;
for(x=0;n!=0;x++)
{
r=n%10;//this is the part
s=s+r*(int)pow(2,x);//im having a hard time
n=n/10;//to figure out
}
cout<<"binary: "<<bin<<"\ndecimal: "<<s;
cout<<"\nenter new number?[y/n]: ";
cin>>a;
}while((a=='y')||(a=='Y'));
system("cls");
}
1)can someone be kind enough to explain that part in the 'for loop'?
2)whenever i enter 1000000000000000,the program stops responding.
i tried to declare everything as unsigned int or even unsigned long but still same problem.