C++ Program to Convert Binary to Hexadecimal

« Previous Program Next Program »

Binary to Hexadecimal in C++

To convert binary to hexadecimal in C++ Programming, you have to ask to the user to enter any number in binary to convert it into hexadecimal, then display the equivalent hexadecimal value on the screen as shown here in the following program.

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 */
void main()
	long int binnum, rem, quot;
	int i=1, j, temp;
	char hexdecnum[100];
	cout<<"Enter Binary Number : ";
	quot = binnum;
		temp = quot % 16;
		// To convert integer into character
		if( temp < 10)
			temp = temp + 48;
			temp = temp + 55;
		hexdecnum[i++]= temp;
		quot = quot / 16;
	cout<<"Equivalent hexadecimal value of "<<binnum<<" is :\n";
	for(j=i-1 ;j>0;j--)

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 Language

You may like the same program in other programming languages:

« Previous Program Next Program »


Quick Links
Signup - Login - Give Online Test