codescracker


c

C Program to Convert Binary to Hexadecimal



« Previous Program Next Program »


Binary to Hexadecimal Conversion in C

To convert binary number to hexadecimal number in C programming, you have to ask to the user to enter the binary number to convert it into hexadecimal number and display the equivalent hexadecimal number

C Programming Code to Convert Binary to Hexadecimal

Following C program ask to the user to enter any number in binary form to convert it into hexadecimal form, then display the result on the screen:

/* C Program - Binary to Hexadecimal Conversion */
		
#include<stdio.h>
#include<conio.h>
void main()
{
	clrscr();
	long int decnum, rem, quot;
	int i=1, j, temp;
	char hexdecnum[100];
	printf("Enter decimal number : ");
	scanf("%ld",&decnum);
	quot = decnum;
	while(quot!=0)
	{
		temp = quot % 16;
		// To convert integer into character
		if( temp < 10)
		{
			temp = temp + 48;
		}
		else
		{
			temp = temp + 55;
		}
		hexdecnum[i++]= temp;
		quot = quot / 16;
	}
	printf("Equivalent hexadecimal value of %d is :\n",decnum);
	for(j=i-1 ;j>0;j--)
	{
		printf("%c",hexdecnum[j]);
	}
	getch();
}

When the above c program is compile and executed, it will produce the following result:

c program to convert binary to hexadecimal

Same Program in Other Programming Language

You may also like same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test