Find the maximum between N and the number formed by reversing 32 | C # program for tha above approach ; Function that obtains the number using said operations from N ; Stores the binary representation of the number N ; Find the binary representation of the number N ; Check for the set bits ; Reverse the string S ; Stores the obtained number ; Calculating the decimal value ; Check for set bits ; Function to find the maximum value between N and the obtained number ; Driver Code
using System ; class GFG { static string ReverseString ( string s ) { char [ ] array = s . ToCharArray ( ) ; Array . Reverse ( array ) ; return new string ( array ) ; } public static int reverseBin ( int N ) { string S = " " ; int i ; for ( i = 0 ; i < 32 ; i ++ ) { if ( ( N & ( 1L << i ) ) != 0 ) S += '1' ; else S += '0' ; } S = ReverseString ( S ) ; int M = 0 ; for ( i = 0 ; i < 32 ; i ++ ) { if ( S [ i ] == '1' ) M += ( 1 << i ) ; } return M ; } static int maximumOfTwo ( int N ) { int M = reverseBin ( N ) ; return Math . Max ( N , M ) ; } static void Main ( ) { int N = 6 ; Console . Write ( maximumOfTwo ( N ) ) ; } }