Binary conversion
List < int > v = new List < int > ( ) ; while ( n != 0 ) { v . Add ( n % 2 ) ; n = n / 2 ; } int j = 0 ; foreach ( int i in v ) { if ( i == 1 ) { return ( int ) Math . Pow ( 2.0 , ( double ) j ) ; } j ++ ; } return 0 ; }