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