Friday, May 25, 2012

C Program That Convert any Binary Number To Hexadecimal Number




Hello friends,today i'm sharing a program that convert any binary number to hexadecimal number,i  try to make this code very easy to all of you,i hope you can easily understand it.If you feel any difficulty than share with me.




#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<ctype.h>
void main()
{
int number,sum=0,rem,x,n,arr[100],i,j,t;
clrscr();
printf("\n\n\n Enter any binary number:");
scanf("%d",&n);
number=n;
x=0;
while(number!=0)
{
rem=number%10;
sum=sum+(rem*pow(2,x));
x++;
number=number/10;
}
i=0;
while(sum!=0)
{
t=sum%16;
if(t>=0&&t<=9)
arr[i]=t;
else if(t==10)
arr[i]='A';
else if(t==11)
arr[i]='B';
else if(t==12)
arr[i]='C';
else if(t==13)
arr[i]='D';
else if(t==14)
arr[i]='E';
else if(t==15)
arr[i]='F';
i++;
sum=sum/16;
}
printf("\n\n\n hexadecimal number of binary number %d is:",n);
for(j=i-1;j>=0;j--)
{
if(isalpha(arr[j]))
printf("%c ",arr[j]);
else
printf("%d ",arr[j]);
}
getch();
}









Thanks Friends.......

No comments:

Post a Comment

Please Give Me Your Views

Popular Posts