Program to convert Hexa | Java 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
public class Main { public static 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 . charAt ( i ) >= 47 && s . charAt ( i ) <= 52 ) { String result = Integer . toBinaryString ( ( int ) s . charAt ( i ) ) ; System . out . print ( result . substring ( result . length ( ) - 4 ) + " ▁ " ) ; } else { String result = Integer . toBinaryString ( ( int ) s . charAt ( i ) - 55 ) ; System . out . print ( result . substring ( result . length ( ) - 4 ) + " ▁ " ) ; } } } public static void main ( String [ ] args ) { String s = "11F " ; HexaDecimaltoBCD ( s ) ; } }