# How to convert Hexadecimal to Binary in C++

In this article, we are going to learn How to convert Hexadecimal to Binary in C++. Here we are going to learn about two number systems one is binary and another is Hexadecimal. Hexadecimal numbers are base 16 numbers and represented in numbers from 0 to 9 and A to F.Binary numbers are base 2 numbers and represented in 0s and 1s.

### C++ program to convert Hexadecimal to binary

In this c++ program, we are converting Hexadecimal to a binary number system by writing some logic without any built-in function.

```#include<iostream>
#include <string.h>

using namespace std;

int main()
{
char hexNum[16+1] = "";
char binNum[64+1] = "";

cin >> hexNum;

for(int k=0; hexNum[k] != '#include<iostream>
#include <string.h>
using namespace std;
int main()
{
char hexNum[16+1] = "";
char binNum[64+1] = "";
cin >> hexNum;
for(int k=0; hexNum[k] != '\0'; k++)
{
switch(hexNum[k])
{
case '0':
strcat(binNum, "0000");
break;
case '1':
strcat(binNum, "0001");
break;
case '2':
strcat(binNum, "0010");
break;
case '3':
strcat(binNum, "0011");
break;
case '4':
strcat(binNum, "0100");
break;
case '5':
strcat(binNum, "0101");
break;
case '6':
strcat(binNum, "0110");
break;
case '7':
strcat(binNum, "0111");
break;
case '8':
strcat(binNum, "1000");
break;
case '9':
strcat(binNum, "1001");
break;
case 'a':
case 'A':
strcat(binNum, "1010");
break;
case 'b':
case 'B':
strcat(binNum, "1011");
break;
case 'c':
case 'C':
strcat(binNum, "1100");
break;
case 'd':
case 'D':
strcat(binNum, "1101");
break;
case 'e':
case 'E':
strcat(binNum, "1110");
break;
case 'f':
case 'F':
strcat(binNum, "1111");
break;
default:
cout << "This is not a Valid HexaDecimal Number. Exiting program.";
exit(0);
}
}
cout << "\nThe Binary equivalent of HexaDecimal number " <<  hexNum << " is " << binNum;
return 0;
}
'; k++)
{
switch(hexNum[k])
{
case '0':
strcat(binNum, "0000");
break;
case '1':
strcat(binNum, "0001");
break;
case '2':
strcat(binNum, "0010");
break;
case '3':
strcat(binNum, "0011");
break;
case '4':
strcat(binNum, "0100");
break;
case '5':
strcat(binNum, "0101");
break;
case '6':
strcat(binNum, "0110");
break;
case '7':
strcat(binNum, "0111");
break;
case '8':
strcat(binNum, "1000");
break;
case '9':
strcat(binNum, "1001");
break;
case 'a':
case 'A':
strcat(binNum, "1010");
break;
case 'b':
case 'B':
strcat(binNum, "1011");
break;
case 'c':
case 'C':
strcat(binNum, "1100");
break;
case 'd':
case 'D':
strcat(binNum, "1101");
break;
case 'e':
case 'E':
strcat(binNum, "1110");
break;
case 'f':
case 'F':
strcat(binNum, "1111");
break;
default:
cout << "This is not a Valid HexaDecimal Number. Exiting program.";
exit(0);
}
}

cout << "\nThe Binary equivalent of HexaDecimal number " <<  hexNum << " is " << binNum;

return 0;
}
```

Output

```Please enter a Hexadecimal Number: f

The Binary equivalent of HexaDecimal number f is 1111