Creating list of the sum of all previous bit values including that bit value
for ( i = 0 ; i < 20 ; i ++ ) { sum += Math . pow ( 2 , i ) ; list . add ( sum ) ; } for ( i = 0 ; i < 20 ; i ++ ) { if ( ( int ) list . get ( i ) >= N ) return ( list . indexOf ( list . get ( i ) ) + 1 ) ; } return 0 ; }