#include<stdio.h>
#include<math.h>
main()
{
long long bin_num,bin;
int dec_num,dec,remainder,i,n;
printf("***************Welcome to Converter***************"); printf("\n\n\n1.Binary to Decimal\n\n2.Decimal to Binary\n\n Enter Your choice : "); switch(n)
{
case 1:
printf("\nPlease, Enter the Binary number : "); bin=bin_num;
i=0;
dec=0;
while(bin_num!=0)
{
remainder=bin_num%10;
dec
=dec
+remainder
*pow(2,i
);i++;
bin_num=bin_num/10;
}
printf("\nThe decimal of %lld is : %d",bin
,dec
); break;
case 2:
printf("\nPlease, Enter the Decimal number : "); dec=dec_num;
i=1;
bin=0;
while(dec_num!=0)
{
remainder=dec_num%2;
dec_num=dec_num/2;
bin=bin+remainder*i;
i=i*10;
}
printf("\nThe binary of %d is : %lld",dec
,bin
); break;
default:
printf("\n SORRY !!! You have Entered a wrong choice."); break;
}
return 0;
}