Who's Online

We have 30 guests and 1 member online

Login Form



RSS FEEDS



Decimal to octal,binary and Hexadecimal conversion PDF Print
User Rating: / 0
PoorBest 
Program Codes - C++ Programming
Written by Mansoorkhan   
Friday, 06 November 2009 03:11

#include
#include
void convrt(int a,int b);
void hexdec(int a);
main()
{
int a,c,r;
char cc;
do
{
clrscr();
printf("\n\n\n\t\tMenu");
printf("\n\n\tConvert decimal to");
printf("\n\n\t1.Binary\n\n\t2.Octal\n\n\t3.Hexadecimal\n\n\t4.Exit\n\n Enter your choice : ");

scanf("%d",&c);
if(c==4)
goto ent;
printf("\n\n Enter the decimal no : ");
scanf("%d",&a);
switch(c)
{
case 1:
convrt(a,2);
break;
case 2:
convrt(a,8);
break;
case 3:
hexdec(a);
break;
}
getch();
printf("\n\n Do you want to continue : ");
cc=getche();
}
while(cc=='y'||cc=='Y');
ent:
getch();
}

void convrt(int a,int b)
{
int n,i=1,p=0;
while(a!=0)
{
n=a%b;
p=p+n*i;
a=a/b;
i=i*10;
}
printf(" result= %d ",p);
}
void hexdec(int a)
{
char h[15];
int uu,r,i;
for(i=0;a!=0;i++)
{
r=a%16;
if(r<=9)
{
//printf("%d",48+r);
h[i]=char(48+r);
}
else if(r>9)
{
h[i]=char(55+r);
}
uu=i;
a=a/16;
}
for(i=uu;i>=0;i--)
printf("%c",h[i]);
}

AddThis Social Bookmark Button
 

Copyright Disclaimer: This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.Thanks to Getkerala

For Latest Technology News and computer tips and tricks