#include <bits/stdc++.h>
using namespace std;
void convert_10_from_2(int n)
{
if(n > 0)
{
int t = n % 2;
convert_10_from_2(n / 2);
cout<<t;
}
}
void convert_10_from_8(int n)
{
if(n > 0)
{
int t = n % 8;
convert_10_from_2(n / 8);
cout<<t;
}
}
void convert_10_from_16(int n)
{
if(n > 0)
{
int t = n % 16;
char Array[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
convert_10_from_16(n / 16);
cout<<Array[t];
}
}
void convert_2_from_10(int n)
{
int count = 0, sum = 0;
while(n != 0)
{
int t = n % 10;
int tong = t * pow(2,count);
sum = sum + tong;
count++;
n = n / 10;
}
cout<<sum;
}
void convert_2_from_8(int n)
{
int count = 0, sum = 0;
while(n != 0)
{
int t = n % 10;
int tong = t * pow(2,count);
sum = sum + tong;
count++;
n = n / 10;
}
convert_10_from_8(sum);
}
void convert_2_from_16(int n)
{
int count = 0, sum = 0;
while(n != 0)
{
int t = n % 10;
int tong = t * pow(2,count);
sum = sum + tong;
count++;
n = n / 10;
}
convert_10_from_16(sum);
}
void convert_8_from_2(int n)
{
int sum = 0 , i = 0;
while(n != 0)
{
int t = n % 10;
sum = sum + pow(8,i)*t;
i++;
n = n / 10;
}
convert_10_from_2(sum);
}
void convert_8_from_10(int n)
{
int sum = 0 , i = 0;
while(n != 0)
{
int t = n % 10;
sum = sum + pow(8,i)*t;
i++;
n = n / 10;
}
cout<<sum;
}
void convert_8_from_16(int n)
{
int sum = 0 , i = 0;
while(n != 0)
{
int t = n % 10;
sum = sum + pow(8,i)*t;
i++;
n = n / 10;
}
convert_10_from_16(sum);
}
void convert_16_from_2(string k)
{
for(int i = 0 ; i < k.size() ; i++)
{
if(k[i] == 'A')
cout<<"1010"<<" ";
if(k[i] == 'A')
cout<<"1010"<<" ";
if(k[i] == 'B')
cout<<"1011"<<" ";
if(k[i] == 'C')
cout<<"1100"<<" ";
if(k[i] == 'D')
cout<<"1101"<<" ";
if(k[i] == 'E')
cout<<"1110"<<" ";
if(k[i] == 'F')
cout<<"1111"<<" ";
if(k[i] == '0')
cout<<"0000"<<" ";
if(k[i] == '1')
cout<<"0001"<<" ";
if(k[i] == '2')
cout<<"0010"<<" ";
if(k[i] == '3')
cout<<"0011"<<" ";
if(k[i] == '4')
cout<<"0100"<<" ";
if(k[i] == '5')
cout<<"0101"<<" ";
if(k[i] == '6')
cout<<"0110"<<" ";
if(k[i] == '7')
cout<<"0111"<<" ";
if(k[i] == '8')
cout<<"1000"<<" ";
if(k[i] == '9')
cout<<"1001"<<" ";
}
}
int main()
{
cout<<"\t--------MODE--------";
cout<<"\n\t|1:Convert 10 to 2 |";
cout<<"\n\t|2:Convert 10 to 8 |";
cout<<"\n\t|3:Convert 10 to 16|";
cout<<"\n\t|4:Convert 2 to 10 |";
cout<<"\n\t|5:Convert 2 to 8 |";
cout<<"\n\t|6:Convert 2 to 16 |";
cout<<"\n\t|7:Convert 8 to 2 |";
cout<<"\n\t|8:Convert 8 to 10 |";
cout<<"\n\t|9:Convert 8 to 16 |";
cout<<"\n\t|10:Convert 16 to 2|";
cout<<"\n\t|0::Exit |";
cout<<"\n\t|Choose ? |";
cout<<"\n\t ___________________";
cout<<"\n\t >->->-End-<-<-<\n";
int choose;
do
{
cout<<endl;
cout<<"\nChoose:";
cin>>choose;
switch(choose)
{
case 0: break;
case 1:
{
int n;
cout<<"Number:";
cin>>n;
cout<<"Convert 10 to 2"<<endl;
convert_10_from_2(n);
break;
}
case 2:
{
int n;
cout<<"Number:";
cin>>n;
cout<<"Convert 10 to 8"<<endl;
convert_10_from_8(n);
break;
}
case 3:
{
int n;
cout<<"Number:";
cin>>n;
cout<<"Convert 10 to 16"<<endl;
convert_10_from_16(n);
break;
}
case 4:
{
int n;
cout<<"Number:";
cin>>n;
cout<<"Convert 2 to 10"<<endl;
convert_2_from_10 (n);
break;
}
case 5:
{
int n;
cout<<"Number:";
cin>>n;
cout<<"Convert 2 to 8"<<endl;
convert_2_from_8(n);
break;
}
case 6:
{
int n;
cout<<"Number:";
cin>>n;
cout<<"Convert 2 to 16"<<endl;
convert_2_from_16(n);
break;
}
case 7:
{
int n;
cout<<"Number:";
cin>>n;
cout<<"Convert 8 to 2"<<endl;
convert_8_from_2(n);
break;
}
case 8:
{
int n;
cout<<"Number:";
cin>>n;
cout<<"Convert 8 to 10"<<endl;
convert_8_from_10(n);
break;
}
case 9:
{
int n;
cout<<"Number:";
cin>>n;
cout<<"Convert 8 to 16"<<endl;
convert_8_from_16(n);
break;
}
case 10:
{
string n;
cout<<"Number:";
cin>>n;
cout<<"Convert 16 to 2"<<endl;
convert_16_from_2(n);
break;
}
}
}
while(choose != 0);
return 0;
}