Given a HexaDecimal Number **N**, the task is to convert the number to its equivalent Binary Coded Decimal.

**Examples:**

Input:11F

Output:0001 0001 1111

Explanation:

Binary of 1 – 0001

Binary of F – 1111

Thus, Equivalent BCD is 0001 0001 1111

Input:A D

Output:1010 1101

Explanation:

Binary of A – 1010

Binary of D – 1101

Thus, Equivalent BCD is 1010 1101

**Approach:** The idea is to iterate over each digit of the given Hexa-Decimal number and find the four digit Binary Equivalent of that digit. Finally, print all the converted digits one by one.

Below is the implementation of the above approach:

## C++

`// C++ implementation to convert the given ` `// HexaDecimal number to its equivalent BCD. ` ` ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to convert ` `// HexaDecimal to its BCD ` `void` `HexaDecimaltoBCD(string s) ` `{ ` ` ` `int` `len = s.length(), check = 0; ` ` ` `int` `num = 0, sum = 0, mul = 1; ` ` ` ` ` `// Iterating through the digits ` ` ` `for` `(` `int` `i = 0; i <= len - 1; i++) { ` ` ` ` ` `// check whether s[i] is a character ` ` ` `// or a integer between 0 to 9 ` ` ` `// and compute its equivalent BCD ` ` ` `if` `(s[i] >= 47 && s[i] <= 52) ` ` ` `cout << bitset<4>(s[i]) ` ` ` `<< ` `" "` `; ` ` ` `else` ` ` `cout << bitset<4>(s[i] - 55) ` ` ` `<< ` `" "` `; ` ` ` `} ` `} ` ` ` `// Driver Code ` `int` `main() ` `{ ` ` ` `string s = ` `"11F"` `; ` ` ` ` ` `// Function Call ` ` ` `HexaDecimaltoBCD(s); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

**Output:**

0001 0001 1111

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Program to Convert Hexadecimal Number to Binary
- Program to Convert Octal to Hexadecimal
- Program to Convert Hexadecimal to Octal
- Convert a binary number to hexadecimal number
- Convert the given BCD to its equivalent Binary form
- Convert the ASCII value sentence to its equivalent string
- Program for Hexadecimal to Decimal
- Program to Convert Octal Number to Binary Number
- Program for decimal to hexadecimal conversion
- Program to convert a given number to words | Set 2
- Program to convert Number in characters
- Program to convert a given number to words
- Program to Convert BCD number into Decimal number
- Program to convert a BCD to Hexa-Decimal Number
- Python program to convert decimal to binary number
- Check whether the binary equivalent of a number ends with "001" or not
- Convert Hexadecimal value String to ASCII value String
- Check whether the binary equivalent of a number ends with given string or not
- Check if a HexaDecimal number is Even or Odd
- Count Hexadecimal Number

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.