Smallest power of 2 consisting of N digits | Function to return smallest power of 2 with N digits ; Iterate through all powers of 2 ; Driver Code
function smallestNum ( n ) { res = 1 ; for ( var i = 2 ; ; i *= 2 ) { var length = parseInt ( Math . log ( i ) / Math . log ( 10 ) ) + 1 ; if ( length == n ) return parseInt ( Math . log ( i ) / Math . log ( 2 ) ) ; } } n = 4 ; document . write ( smallestNum ( n ) ) ;