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