Skip to content

Commit a680634

Browse files
authored
Added a code
Hexadecimal to binary convertor.
1 parent d16cc29 commit a680634

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

Vivek Kumar

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// C++ program to convert
2+
// Hexadecimal number to Binary
3+
4+
#include <bits/stdc++.h>
5+
using namespace std;
6+
7+
// function to convert
8+
// Hexadecimal to Binary Number
9+
void HexToBin(string hexdec)
10+
{
11+
long int i = 0;
12+
13+
while (hexdec[i]) {
14+
15+
switch (hexdec[i]) {
16+
case '0':
17+
cout << "0000";
18+
break;
19+
case '1':
20+
cout << "0001";
21+
break;
22+
case '2':
23+
cout << "0010";
24+
break;
25+
case '3':
26+
cout << "0011";
27+
break;
28+
case '4':
29+
cout << "0100";
30+
break;
31+
case '5':
32+
cout << "0101";
33+
break;
34+
case '6':
35+
cout << "0110";
36+
break;
37+
case '7':
38+
cout << "0111";
39+
break;
40+
case '8':
41+
cout << "1000";
42+
break;
43+
case '9':
44+
cout << "1001";
45+
break;
46+
case 'A':
47+
case 'a':
48+
cout << "1010";
49+
break;
50+
case 'B':
51+
case 'b':
52+
cout << "1011";
53+
break;
54+
case 'C':
55+
case 'c':
56+
cout << "1100";
57+
break;
58+
case 'D':
59+
case 'd':
60+
cout << "1101";
61+
break;
62+
case 'E':
63+
case 'e':
64+
cout << "1110";
65+
break;
66+
case 'F':
67+
case 'f':
68+
cout << "1111";
69+
break;
70+
default:
71+
cout << "\nInvalid hexadecimal digit "
72+
<< hexdec[i];
73+
}
74+
i++;
75+
}
76+
}
77+
78+
// driver code
79+
int main()
80+
{
81+
82+
// Get the Hexadecimal number
83+
char hexdec[100] = "1AC5";
84+
85+
// Convert HexaDecimal to Binary
86+
cout << "\nEquivalent Binary value is : ";
87+
HexToBin(hexdec);
88+
89+
return 0;
90+
}

0 commit comments

Comments
 (0)