'm trying to convert any number system up to base 16 to another base system. Both bases are given by the user as well as target number. Im trying to get my output to look like this-
Base number system-2
Target system-16
value in base-1110110011
The 1110110011 in base 2 is equal to 3B3 in base 16;
#include <math.h>
#include<iostream>
#include<string>
usingnamespace std;
int main()
{
string str;
string temp;
string digits("123456789ABCDEF");
int base, value, target;
int sum=0;
cout << "Enter the base : ";
cin >>base;
//Entering number system oct, hex or binary
cout<<"Enter the number : ";
cin>>str;
cout<<"Enter the target number system"<<endl;
cin>>target;
//Check for hex values
for (int j=0; j = str.size()-1; j--)
{
if(std[j]=a||A)
std[j]=10;
elseif(std[j]=b||B)
std[j]=11;
elseif(std[j]=c||C)
std[j]=12;
elseif(std[j]=d||D)
std[j]=13;
elseif(std[j]=e||E)
std[j]=14;
elseif(std[j]=f||F)
std[j]=15;
}
//getting to decimal for base conversion
for (int i=0; i = str.size()-1; digit=0; i>0; i--; digit++)
{
temp=str[i];
value=atoi(temp.c_str());
sum+=value*pow((float)base, digit);
}
//Base Conversion
int place=0;
number=sum;
while(number>0)
{
digit[place]=number mod target;
number=number div target;
place=place+1
}
//Final output
cout<<"The "<<std<< "in base "<<base<< "is equal to "<<number<<"in base " << target;
return 0;
}