Creating list of the sum of all previous bit values including that bit value
for ( i = 0 ; i < 20 ; i ++ ) { sum += parseInt ( Math . pow ( 2 , i ) , 10 ) ; list . push ( sum ) ; } for ( i = 0 ; i < 20 ; i ++ ) { if ( list [ i ] >= N ) return ( i + 1 ) ; } return 0 ; }