Convert Hexadecimal to Binary Program in C++

Google Advertisements

Prev Tutorial Next Tutorial

C++ program to Convert Hexadecimal to Binary

To convert hexadecimal number to binary number in C++ programming, We have to ask to the user to enter the hexadecimal number to convert it into binary number to display the equivalent value in binary format on screen.

Example

0=0000
1=0001
2=0010
3=0011
4=0100
5=0101
6=0110
7=0111
8=1000
9=1001
A=1010 (decimal 10)
B=1011 (decimal 11)
C=1100 (decimal 12)
D=1101 (decimal 13)
E=1110 (decimal 14)
F=1111 (decimal 15)

Example

Input Hexadecimal Number : F
Euivalent Binary Number : 1111

Input Hexadecimal Number : 3F
Euivalent Binary Number : 111111

Input Hexadecimal Number : 2A
Euivalent Binary Number : 101010

C++ program to convert Hexadecimal to Binary

#include<iostream.h>
#include<conio.h>

void main()
{
	clrscr();
	long int i=0;
	char binnum[100], hexdec[100];
	cout<<"Enter any Hexadecimal Number: ";
	cin>>hexdec;
	cout<<"\nEquivalent Binary Value is: ";
	while(hexdec[i])
	{
		switch(hexdec[i])
		{
			case '0' : cout<<"0000";
				break;
			case '1' : cout<<"0001";
				break;
			case '2' : cout<<"0010";
				break;
			case '3' : cout<<"0011";
				break;
			case '4' : cout<<"0100";
				break;
			case '5' : cout<<"0101";
				break;
			case '6' : cout<<"0110";
				break;
			case '7' : cout<<"0111";
				break;
			case '8' : cout<<"1000";
				break;
			case '9' : cout<<"1001";
				break;
			case 'A' : cout<<"1010";
				break;
			case 'B' : cout<<"1011";
				break;
			case 'C' : cout<<"1100";
				break;
			case 'D' : cout<<"1101";
				break;
			case 'E' : cout<<"1110";
				break;
			case 'F' : cout<<"1111";
				break;
			case 'a' : cout<<"1010";
				break;
			case 'b' : cout<<"1011";
				break;
			case 'c' : cout<<"1100";
				break;
			case 'd' : cout<<"1101";
				break;
			case 'e' : cout<<"1110";
				break;
			case 'f' : cout<<"1111";
				break;
			default : cout<<"\nInvalid Hexadecimal Digit "<<hexdec[i];
	}
   i++;
  }
 getch();
}

Output

Enter any Hexadecimal Number: 2C
Equivalent Binary Value is: 101100
c++ program to convert hexadecimal to binary
Prev Tutorial Next Tutorial

Google Advertisements

We have more than 5 Groups which have 500000+ Members and some Pages have more than 100000+ members. For Advertisement contact on [email protected] or 8076671483

Buy This Ad Space @$50 per Month, Ad Size 600X200 Contact on: [email protected] or 8076671483

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

Classpath variable is set for providing a path for predefined Java classes which is used in our application. All classes are available in lib/rt.jar so we set classpath upto lib/rt.jar. Difference between path and classpath in Java

Cloud computing is the on demand availability of computer system resources, especially data storage and computing power, without direct active management by the user. Cloud Computing Tutorial

College Projects Related to Java, AWT, C Projects for College, C++ Projects for College, Android Projects. Download Java C C++ Projects

Download Projects

Adsense Advertisements


Buy This ads Space 8076671483

Buy This Ad Space @$120 per Month, Ad Size 300X600 Contact on: [email protected] or 8076671483 Try this Keyword C++ Programs