Professional Documents
Culture Documents
h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
long int bin_to_dec(char *);
int *bin_to_oct(char *);
long int oct_to_dec(long int);
int *oct_to_bin(long int);
void oct_to_hex(long int);
long int hex_to_dec(char *);
int *hex_to_bin(char *);
int *hex_to_oct(char *);
void bin_to_hex(char *);
float binfr_to_decfr(char *);
void binfr_to_octfr(char *);
void binfr_to_hexfr(char *);
void binry_to_other();
void octl_to_other();
int *dec_to_bin(long int);
int *dec_to_oct(long int);
void dec_to_hex(long int);
void dec_to_binfr(long double);
void dec_to_octfr(long double);
void dec_to_hexfr(long double);
int i,*p,k,local,count;
int z[100];
double v=0;
float f;
long int l=0,d,s;
char *ptr,*ptr1,*ptr2;
long int b,temp;
main()
{
char reply;
int choice;
float a;
long double c;
int *rec;
char *str=(char *)malloc(sizeof(char)*100);
do
{
printf("1) Decimal to Binary \n\t\t\t4) Binary to Decimal \n");
printf("2) Decimal to Octal \n\t\t\t5) Binary to Octal
\n");
printf("3) Decimal to hexadecimal
\n\t\t\t6) Binary to hexadecima
l
\n\n \n");
printf("7) Octal to Decimal \n\t\t\t10) Hexadecimal to Decimal \n");
printf("8) Octal to Binary \n\t\t\t11) Hexadecimal to Binary\n");
printf("9) Octal to Hexadecimal
\n\t\t\t12) Hexadecimal to
Octal\n");
printf("Press 0 to Quit\n");
z:
printf("\nEneter choice: ");
scanf("%d",&choice);
do
{
switch(choice)
{
case 1:
do
{
printf("\nEnter a Decimal number:");
scanf("%f",&a);
b=(int)a;
c=a-b;
if(a<0)
{
printf("Not Possible\n");
printf("Try Again\n");
}
}while(a<0);
printf("\nBinary =");
rec=dec_to_bin(b);
for(i=i-1;i>=0;i--)
printf("%d",*(rec+i));
break;
case 2:
do
{
printf("\nEnter a Decimal number:");
scanf("%f",&a);
b=(int)a;
c=a-b;
if(a<0)
{
printf("Error.\n");
}
}while(a<0);
printf("\nOctal=");
rec=dec_to_oct(b);
for(i=i-1;i>=0;i--)
printf("%d",*(rec+i));
break;
case 3:
do
{
printf("\nEnter a Decimal number:");
scanf("%f",&a);
b=(int)a;
c=a-b;
if(a<0)
{
printf("Error ");
}
}while(a<0);
printf("\nHexadecimal=");
dec_to_hex(b);
break;
case 4:
binry_to_other();
if(*(ptr2)!='\0')
printf("\nDecimal%f\n\n",bin_to_dec(ptr1)+binfr_to_decfr(ptr2))
;
else
printf("\nDecimal%ld\n\n",bin_to_dec(ptr1));
break;
case 5:
binry_to_other();
rec=bin_to_oct(ptr1);
printf("Octal=");
for(i=i-1;i>=0;i--)
printf("%d",*(rec+i));
break;
case 6:
binry_to_other();
printf("\nHexadecimal=");
for(i=i-1;i>=0;i--)
bin_to_hex(ptr1);
break;
case 7:
octl_to_other();
s=oct_to_dec(b);
printf("\nDecimal=%ld\n\n",s);
break;
case 8:
octl_to_other();
rec=oct_to_bin(b);
printf("\nBinary=");
for(i=i-1;i>=0;i--)
printf("%d",*(rec+i));
printf("\n\n");
break;
case 9:
octl_to_other();
printf("\nHexadecimal=");
oct_to_hex(b);
break;
case 10:
printf("Enter a hexa number:");
scanf("%s",str);
for(l=0;*(str+l)!=NULL;l++);
printf("\nDecimal=%ld\n\n",hex_to_dec(str));
break;
case 11:
printf("Enter a hexa number:");
scanf("%s",str);
for(l=0;*(str+l)!=NULL;l++);
rec=hex_to_bin(str);
printf("\nBinary=");
for(i=i-1;i>=0;i--)
printf("%d",*(rec+i));
printf("\n\n");
break;
case 12:
printf("Enter a hexa number:");
scanf("%s",str);
for(l=0;*(str+l)!=NULL;l++);
rec=hex_to_oct(str);
printf("\nOctal=");
for(i=i-1;i>=0;i--)
printf("%d",*(rec+i));
printf("\n\n");
break;
case 0:
exit(0);
default:
printf("\n\n**\tINVALID \t**\n\n");
getchar();goto z;
}
b:
getchar();
printf("\nPress z to continue.Press x to go to main menu.\n");
scanf("%c",&reply);
if(reply!='x'&&reply!='z')
{
printf("\n\nINVALID CHOICE\n\n");
goto b;
}
}while(reply!='x');
}while(reply!='z');
getch();
}
int * dec_to_bin(long int a)
{
i=0,v=0;
if(a==0)
{
z[0]=0;
i++;
}
while(a!=0)
{
z[i]=a%2;
a=a/2;
i++;
}
p=&z[0];
return (p);
}
f+=v*m;
i++;
}
return(f);
}
long int oct_to_dec(long int b)
{
int s=0;
for(i=0;b>0;i++)
{
k=b%10;
b=b/10;
s+=k*(int)pow(8,i);
}
return(s);
}
int *oct_to_bin(long int b)
{
s=oct_to_dec(b);
return (dec_to_bin(s));
}
void oct_to_hex(long int b)
{
s=oct_to_dec(b);
dec_to_hex(s);
}
}
return (d);
}
local=i;
if(tr)
{
int k=0;
while(*(ptr+i)!=NULL)
{
*(ptr2+k)=*(ptr+i);
i++;
k++;
}
*(ptr2+k)='\0';
for(l=0;*(ptr+l)!='.';l++);
}
else
{
*(ptr2)='\0';
for(l=0;*(ptr+l)!='\0';l++);
}
}
void octl_to_other()
{
int tp;
do
{ p: tp=0;
printf("\nEnter an Octal Number:");
scanf("%ld",&b);
temp=b;
if(temp<0)
{
printf("Error\n\n");
goto p;
}
for(i=0;temp>0;i++)
{
if(temp%10>7&&temp%10<=9)
{
printf("\nINVALID\n");
tp=1;
break;
}
temp=temp/10;
}
}while(tp);
}