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
using System ; class GFG { static void HexaDecimaltoBCD ( string s ) { int len = s . Length ; for ( int i = 0 ; i <= len - 1 ; i ++ ) { if ( s [ i ] >= 47 && s [ i ] <= 52 ) { string result = Convert . ToString ( ( int ) s [ i ] , 2 ) ; Console . Write ( result . Substring ( result . Length - 4 ) + " ▁ " ) ; } else { string result = Convert . ToString ( ( int ) s [ i ] - 55 , 2 ) ; Console . Write ( result . Substring ( result . Length - 4 ) + " ▁ " ) ; } } } static void Main ( ) { string s = "11F " ; HexaDecimaltoBCD ( s ) ; } }