Smallest power of 2 consisting of N digits | Function to return smallest power of 2 consisting of N digits ; calculate log2 N indirectly using log ( ) method ; Driver code
function smallestNum ( n ) { let power = log2 ( 10 ) ; return Math . ceil ( ( n - 1 ) * power ) ; } function log2 ( N ) { return ( Math . log ( N ) / Math . log ( 2 ) ) ; } let n = 4 ; document . write ( smallestNum ( n ) ) ;