Find the number obtained after concatenation of binary representation of M and N | C # implementation of the approach ; Function to convert decimal number n to its binary representation stored as an array [ ] arr ; Funtion to convert the number represented as a binary array [ ] arr into its decimal equivalent ; Function to concatenate the binary numbers and return the decimal result ; Number of bits in both the numbers ; Convert the bits in both the integers to the arrays [ ] a and [ ] b ; c [ ] will be the binary array for the result ; Update the c [ ] array ; Return the decimal equivalent of the result ; Driver code
using System ; class GFG { static void decBinary ( int [ ] arr , int n ) { int k = ( int ) ( Math . Log ( n ) / Math . Log ( 2 ) ) ; while ( n > 0 ) { arr [ k -- ] = n % 2 ; n /= 2 ; } } static int binaryDec ( int [ ] arr , int n ) { int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) ans += arr [ i ] << ( n - i - 1 ) ; return ans ; } static int concat ( int m , int n ) { int k = ( int ) ( Math . Log ( m ) / Math . Log ( 2 ) ) + 1 ; int l = ( int ) ( Math . Log ( n ) / Math . Log ( 2 ) ) + 1 ; int [ ] a = new int [ k ] ; int [ ] b = new int [ l ] ; int [ ] c = new int [ k + l ] ; decBinary ( a , m ) ; decBinary ( b , n ) ; int iN = 0 ; for ( int i = 0 ; i < k ; i ++ ) c [ iN ++ ] = a [ i ] ; for ( int i = 0 ; i < l ; i ++ ) c [ iN ++ ] = b [ i ] ; return ( binaryDec ( c , k + l ) ) ; } public static void Main ( String [ ] args ) { int m = 4 , n = 5 ; Console . WriteLine ( concat ( m , n ) ) ; } }