Program to Convert Hexadecimal Number to Binary | C # program to convert Hexadecimal number to Binary ; function to convert Hexadecimal to Binary Number ; Driver code ; Get the Hexadecimal number ; Convert HexaDecimal to Binary
class GFG { static void HexToBin ( char [ ] hexdec ) { int i = 0 ; while ( hexdec [ i ] != ' \u0000' ) { switch ( hexdec [ i ] ) { case '0' : System . Console . Write ( "0000" ) ; break ; case '1' : System . Console . Write ( "0001" ) ; break ; case '2' : System . Console . Write ( "0010" ) ; break ; case '3' : System . Console . Write ( "0011" ) ; break ; case '4' : System . Console . Write ( "0100" ) ; break ; case '5' : System . Console . Write ( "0101" ) ; break ; case '6' : System . Console . Write ( "0110" ) ; break ; case '7' : System . Console . Write ( "0111" ) ; break ; case '8' : System . Console . Write ( "1000" ) ; break ; case '9' : System . Console . Write ( "1001" ) ; break ; case ' A ' : case ' a ' : System . Console . Write ( "1010" ) ; break ; case ' B ' : case ' b ' : System . Console . Write ( "1011" ) ; break ; case ' C ' : case ' c ' : System . Console . Write ( "1100" ) ; break ; case ' D ' : case ' d ' : System . Console . Write ( "1101" ) ; break ; case ' E ' : case ' e ' : System . Console . Write ( "1110" ) ; break ; case ' F ' : case ' f ' : System . Console . Write ( "1111" ) ; break ; default : System . Console . Write ( " STRNEWLINE Invalid ▁ hexadecimal ▁ digit ▁ " + hexdec [ i ] ) ; break ; } i ++ ; } } static void Main ( ) { string s = "1AC5" ; char [ ] hexdec = new char [ 100 ] ; hexdec = s . ToCharArray ( ) ; System . Console . Write ( " Equivalent ▁ Binary ▁ value ▁ is ▁ : ▁ " ) ; try { HexToBin ( hexdec ) ; } catch ( System . IndexOutOfRangeException ) { System . Console . Write ( " " ) ; } } }