#include<iostream.h>
#include<math.h>
#include<conio.h>

void main()
{
  int choice;

  do{
      clrscr();
      cout<<"\n\n\t\tEnter choice\n\n\n";
      cout<<"\n1  decimal to all			5  binary to all\n";
      cout<<"\n2  decimal to binary			6  binary to decimal\n";
      cout<<"\n3  decimal to hexadecimal		7  binary to octal\n";
      cout<<"\n4  decimal to octal			8  binary to hexadecimal\n";

      cout<<"\n\n\n9 octal to all		        	13 hexadecimal to all\n";
      cout<<"\n10 octal to binary			14 hexadecimal to decimal\n";
      cout<<"\n11 octal to hexadecimal			15 hexadecimal to octal\n";
      cout<<"\n12 octal to decimal			16 hexadecimal to binary\n";

      cout<<"\n\n\n                   0   exit\n";
      cin>>choice;
      clrscr();
      long a1=0;
      int check=0,check1=0,check2=0;//,check3=0;
      char x1,x2,x3,x4,x5,y1,y2,y3,y4,y5;
      switch(choice)
	{
	  case 1://decimal to all
		 {
			cout<<"\n enter the positive decimal no=";
			cin>>a1;
			check=1;

		 }//break;
	  case 2://decimal to binary
		 {
			int a,r;
		    a=a1;
		    if(!check)
		      {
			cout<<"\n enter the positive decimal no=";
			cin>>a;
		      }


			cout<<"\nbinary==\t\t\t\t";
			while(a>=1)
			 {
			   r=a%2;
			   cout<<"\b\b"<<r;
			   a=a/2;
			 }
			   if(!check)
			getch();

		 }
		  if(!check)
		 break;
	  case 3://decimal to hexadecimal
		 {
			int a,r;
			a=a1;
		    if(!check)
		     {
			cout<<"\n enter the positive decimal no=";
			cin>>a;
		     }
			cout<<"\nhex==\t\t\t\t";
			while(a>=1)
			 {
				r=a%16;
				if(r<10)
				{
				   cout<<"\b\b"<<r;
				}
				else
				{
				  switch(r)
				  {
				   case 10:cout<<"\b\b"<<"A"; break;
				   case 11:cout<<"\b\b"<<"B"; break;
				   case 12:cout<<"\b\b"<<"C"; break;
				   case 13:cout<<"\b\b"<<"D"; break;
				   case 14:cout<<"\b\b"<<"E"; break;
				   case 15:cout<<"\b\b"<<"F"; break;
				  }
				}
				a=a/16;
			 }
			    if(!check)
			 getch();
		 }
		 if(!check)
		 break;
	  case 4://decimal to octal
		 {
			int a,r;
			a=a1;
		      if(!check)
		      {
			cout<<"\n enter the positive decimal no=";
			cin>>a;
		      }
			cout<<"\noct==\t\t\t\t";
			while(a>=1)
			{
			   r=a%8;
			   cout<<"\b\b"<<r;
			   a=a/8;
			}
			getch();
			check=0;

		 }
		 break;
	  case 5://binary to all
		 {
		    cout<<"\n enter the binary no=";
		    cin>>a1;
		    check1=1;

		 }//break;
	  case 6://binary to decimal
		 {
		    long a,r;
		    long power=0,sum=0;
		    a=a1;
		  if(!check1)
		  {
		    cout<<"\n enter the binary no=";
		    cin>>a;
		  }
		    cout<<"\ndecimal==\t\t\t\t";
		    while(a>=1)
		     {
			   r=a%10;
			   sum = sum + (pow(2,power++)*r);
			   a=a/10;
		     }
		   cout<<sum;
		   if(!check1)
		   getch();

		 }
		  if(!check1)
		 break;
	  case 7://binary to octal
		 {
		    int count=0;
		    long a,r;
		    long power=0,sum=0;
		    a=a1;
		  if(!check1)
		  {
		    cout<<"\n enter the binary no=";
		    cin>>a;
		  }
		    cout<<"\noct==\t\t\t\t";
		    while(a>=1)
		     {
			   if(count==3)
			    {
			      count=0;
			      cout<<"\b\b"<<sum;
			      sum=0;
			      power=0;
			    }
			   r=a%10;
			   sum = sum + (pow(2,power++)*r);
			   a=a/10;
			   count++;
		     }
		   cout<<"\b\b"<<sum;
		    if(!check1)
		   getch();

		 }
		  if(!check1)
		 break;
	  case 8://binary to hexadecimal
		 {
		    int count=0;
		    long a,r;
		    long power=0,sum=0;
		    a=a1;
		 if(!check1)
		  {
		    cout<<"\n enter the binary no=";
		    cin>>a;
		  }
		    cout<<"\nhex==\t\t\t\t";
		    while(a>=1)
		     {
			   if(count==4)
			    {
			      count=0;
				if(sum<10)
				{
				   cout<<"\b\b"<<sum;
				}
				else
				{
				  switch(sum)
				  {
				   case 10:cout<<"\b\b"<<"A"; break;
				   case 11:cout<<"\b\b"<<"B"; break;
				   case 12:cout<<"\b\b"<<"C"; break;
				   case 13:cout<<"\b\b"<<"D"; break;
				   case 14:cout<<"\b\b"<<"E"; break;
				   case 15:cout<<"\b\b"<<"F"; break;
				  }
				}
			      sum=0;
			      power=0;
			    }
			   r=a%10;
			   sum = sum + (pow(2,power++)*r);
			   a=a/10;
			   count++;
		     }
			if(sum<10)
			{
			   cout<<"\b\b"<<sum;
			}
			else
			{
			  switch(sum)
			  {
			   case 10:cout<<"\b\b"<<"A"; break;
			   case 11:cout<<"\b\b"<<"B"; break;
			   case 12:cout<<"\b\b"<<"C"; break;
			   case 13:cout<<"\b\b"<<"D"; break;
			   case 14:cout<<"\b\b"<<"E"; break;
			   case 15:cout<<"\b\b"<<"F"; break;
			  }
			}

		   getch();
		   check1=0;
		 }break;
	  case 9://octal to all
		 {
			cout<<"\n enter the octal no=";
			cin>>a1;
			check2=1;

		 }//break;
	  case 10://octal to binary
		 {
			long a,r;
			long s;
			int count=0;
			a=a1;
		 if(!check2)
		     {
			cout<<"\n enter the octal no=";
			cin>>a;
		     }
			cout<<"\nbin==\t\t\t\t";

			while(a>=1)
			{
			   r=a%10;
			//=============

				while(r>=1)
				{  count++;
				   s=r%2;
				   cout<<"\b\b"<<s;
				   r=r/2;
				}
			   if(count==0)
			     cout<<"\b\b0\b\b0\b\b0";
			   if(count==1)
			     cout<<"\b\b0\b\b0";
			   if(count==2)
			     cout<<"\b\b0";

			   count=0;
			   a=a/10;
			}
		 if(!check2)
		 getch();

		 }
		 if(!check2)
		 break;
	  case 11://octal to hexadecimal
		 {
			long a,r;
			long s;
			int count=0,sum=0,power=0;
			a=a1;
		 if(!check2)
		   {
			cout<<"\n enter the octal no=";
			cin>>a;
		   }
			while(a>=1)
			{
			   r=a%10;
				while(r>=1)
				{
				   count++;
				   s=r%2;
				   sum = sum + (pow(2,power++)*s);
				   r=r/2;
				}
				   if(count==0)
				      power+=3;
				   if(count==1)
				      power+=2;
				   if(count==2)
				      power+=1;
				   count=0;
				   a=a/10;
				}

			cout<<"\nhex==\t\t\t";
			while(sum>=1)
			 {
				r=sum%16;
				if(r<10)
				{
				   cout<<"\b\b"<<r;
				}
				else
				{
				  switch(r)
				  {
				   case 10:cout<<"\b\b"<<"A"; break;
				   case 11:cout<<"\b\b"<<"B"; break;
				   case 12:cout<<"\b\b"<<"C"; break;
				   case 13:cout<<"\b\b"<<"D"; break;
				   case 14:cout<<"\b\b"<<"E"; break;
				   case 15:cout<<"\b\b"<<"F"; break;
				  }
				}
				sum=sum/16;
			 }
		 if(!check2)
			getch();

		 }
		 if(!check2)
		 break;
	  case 12://octal to decimal
		 {
			long a,r;
			long s;
			int count=0,sum=0,power=0;
			a=a1;
		 if(!check2)
		    {
			cout<<"\n enter the octal no=";
			cin>>a;
		    }
			cout<<"\ndec==\t\t\t\t";

			while(a>=1)
			{
			   r=a%10;
				while(r>=1)
				{
				   count++;
				   s=r%2;
				   sum = sum + (pow(2,power++)*s);
				   r=r/2;
				}
				   if(count==0)
				      power+=3;
				   if(count==1)
				      power+=2;
				   if(count==2)
				      power+=1;
				   count=0;
				   a=a/10;
				}
			   cout<<sum;
			getch();
		 }break;
	  case 13://hexadecimal to all
		 {

		 }break;
	  case 14://hexadecimal to decimal
		 {
		    long a;
		    char z1,z2,z3,z4,z5;
		    cout<<"\nenter a five digit hexadecimal number eg 00fac== ";

		     z5=getche();
				 x5=z5-48;
				 switch(z5)
				  {
				   case 'a':x5=10; break;
				   case 'b':x5=11; break;
				   case 'c':x5=12; break;
				   case 'd':x5=13; break;
				   case 'e':x5=14; break;
				   case 'f':x5=15; break;
				  }

		     z4=getche();
				 x4=z4-48;
				 switch(z4)
				  {
				   case 'a':x4=10; break;
				   case 'b':x4=11; break;
				   case 'c':x4=12; break;
				   case 'd':x4=13; break;
				   case 'e':x4=14; break;
				   case 'f':x4=15; break;
				  }

		     z3=getche();
				 x3=z3-48;
				 switch(z3)
				  {
				   case 'a':x3=10; break;
				   case 'b':x3=11; break;
				   case 'c':x3=12; break;
				   case 'd':x3=13; break;
				   case 'e':x3=14; break;
				   case 'f':x3=15; break;
				  }

		     z2=getche();
				 x2=z2-48;
				 switch(z2)
				  {
				   case 'a':x2=10; break;
				   case 'b':x2=11; break;
				   case 'c':x2=12; break;
				   case 'd':x2=13; break;
				   case 'e':x2=14; break;
				   case 'f':x2=15; break;
				  }

		     z1=getche();
				 x1=z1-48;
				 switch(z1)
				  {
				   case 'a':x1=10; break;
				   case 'b':x1=11; break;
				   case 'c':x1=12; break;
				   case 'd':x1=13; break;
				   case 'e':x1=14; break;
				   case 'f':x1=15; break;
				  }

		     a = (x5*pow(16,4))+(x4*pow(16,3))+(x3*pow(16,2))+(x2*16)+x1;
		     cout<<"\n\n"<<a;
		     getch();
		 }break;
	  case 15://hexadecimal to octal
		 {
		    long a,r;
		    char z1,z2,z3,z4,z5;
		    cout<<"\nenter a five digit hexadecimal number eg 00fac== ";

		     z5=getche();
				 x5=z5-48;
				 switch(z5)
				  {
				   case 'a':x5=10; break;
				   case 'b':x5=11; break;
				   case 'c':x5=12; break;
				   case 'd':x5=13; break;
				   case 'e':x5=14; break;
				   case 'f':x5=15; break;
				  }

		     z4=getche();
				 x4=z4-48;
				 switch(z4)
				  {
				   case 'a':x4=10; break;
				   case 'b':x4=11; break;
				   case 'c':x4=12; break;
				   case 'd':x4=13; break;
				   case 'e':x4=14; break;
				   case 'f':x4=15; break;
				  }

		     z3=getche();
				 x3=z3-48;
				 switch(z3)
				  {
				   case 'a':x3=10; break;
				   case 'b':x3=11; break;
				   case 'c':x3=12; break;
				   case 'd':x3=13; break;
				   case 'e':x3=14; break;
				   case 'f':x3=15; break;
				  }

		     z2=getche();
				 x2=z2-48;
				 switch(z2)
				  {
				   case 'a':x2=10; break;
				   case 'b':x2=11; break;
				   case 'c':x2=12; break;
				   case 'd':x2=13; break;
				   case 'e':x2=14; break;
				   case 'f':x2=15; break;
				  }

		     z1=getche();
				 x1=z1-48;
				 switch(z1)
				  {
				   case 'a':x1=10; break;
				   case 'b':x1=11; break;
				   case 'c':x1=12; break;
				   case 'd':x1=13; break;
				   case 'e':x1=14; break;
				   case 'f':x1=15; break;
				  }

		     a = (x5*pow(16,4))+(x4*pow(16,3))+(x3*pow(16,2))+(x2*16)+x1;


		    cout<<"\noct==\t\t\t\t";
			while(a>=1)
			{
			   r=a%8;
			   cout<<"\b\b"<<r;
			   a=a/8;
			}
			getch();


		 }break;
	  case 16://hexadecimal to binary
		 {
		    long a,r;
		    char z1,z2,z3,z4,z5;
		    cout<<"\nenter a five digit hexadecimal number eg 00fac== ";

		     z5=getche();
				 x5=z5-48;
				 switch(z5)
				  {
				   case 'a':x5=10; break;
				   case 'b':x5=11; break;
				   case 'c':x5=12; break;
				   case 'd':x5=13; break;
				   case 'e':x5=14; break;
				   case 'f':x5=15; break;
				  }

		     z4=getche();
				 x4=z4-48;
				 switch(z4)
				  {
				   case 'a':x4=10; break;
				   case 'b':x4=11; break;
				   case 'c':x4=12; break;
				   case 'd':x4=13; break;
				   case 'e':x4=14; break;
				   case 'f':x4=15; break;
				  }

		     z3=getche();
				 x3=z3-48;
				 switch(z3)
				  {
				   case 'a':x3=10; break;
				   case 'b':x3=11; break;
				   case 'c':x3=12; break;
				   case 'd':x3=13; break;
				   case 'e':x3=14; break;
				   case 'f':x3=15; break;
				  }

		     z2=getche();
				 x2=z2-48;
				 switch(z2)
				  {
				   case 'a':x2=10; break;
				   case 'b':x2=11; break;
				   case 'c':x2=12; break;
				   case 'd':x2=13; break;
				   case 'e':x2=14; break;
				   case 'f':x2=15; break;
				  }

		     z1=getche();
				 x1=z1-48;
				 switch(z1)
				  {
				   case 'a':x1=10; break;
				   case 'b':x1=11; break;
				   case 'c':x1=12; break;
				   case 'd':x1=13; break;
				   case 'e':x1=14; break;
				   case 'f':x1=15; break;
				  }

		     a = (x5*pow(16,4))+(x4*pow(16,3))+(x3*pow(16,2))+(x2*16)+x1;
			cout<<"\nbinary==\t\t\t\t";
			while(a>=1)
			 {
			   r=a%2;
			   cout<<"\b\b"<<r;
			   a=a/2;
			 }
getch();
		 }break;
	}
    }while(choice!=0);
}//end main