Find the number obtained after concatenation of binary representation of M and N | C ++ implementation of the approach ; Utility function to calculate binary length of a number . ; Function to concatenate the binary numbers and return the decimal result ; find binary length of n ; left binary shift m and then add n ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int getBinaryLength ( int n ) { int length = 0 ; while ( n > 0 ) { length += 1 ; n /= 2 ; } return length ; } int concat ( int m , int n ) { int length = getBinaryLength ( n ) ; return ( m << length ) + n ; } int main ( ) { int m = 4 , n = 5 ; cout << concat ( m , n ) ; return 0 ; }