Find the number obtained after concatenation of binary representation of M and N | Java 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
import java . util . * ; class GFG { public static int getBinaryLength ( int n ) { int length = 0 ; while ( n > 0 ) { length += 1 ; n /= 2 ; } return length ; } public static int concat ( int m , int n ) { int length = getBinaryLength ( n ) ; return ( m << length ) + n ; } public static void main ( String [ ] args ) throws Exception { int m = 4 , n = 5 ; System . out . println ( concat ( m , n ) ) ; } }