Hexadecimal to binary conversion in C by R4R Team

Hexadecimal number :
Consists of 16 elements
range : 0 to 9 then 'A' to 'F'

Binary number :
Consists of 2 elements
range : 0 to 1


program-

#include< stdio.h>
#include< math.h>
int main() {
int n,num=0,i=0,decimal=0;
printf("Enter Hexadecimal number\n");
scanf("%d",&n);
//Hexadecimal to decimal
while(n)
{
num=n%10;
num=num*pow(16,i++);
decimal=decimal+num;
n=n/10;
}
//decimal to binary
num=0;
while(decimal)
{
num=num*10+decimal%2;
decimal=decimal/2;
}
printf("Binary is %d",num);
}


output-

Enter Hexadecimal number
41
Binary is 1000001

-In this program, we take an input in the Hexadecimal form then try to find its binary equivalent.
-Firstly we change Hexadecimal to decimal and then decimal to binary.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!