Largest number M having bit count of N such that difference between their OR and XOR value is maximized | Java program for the above approach ; Function to find the largest number M having the same length in binary form as N such that the difference between N | M and N ^ M is maximum ; Find the most significant bit of N ; Initialize M ; Set all the bits of M ; Return the answer ; Driver Code ; Given number N ; Function call
import java . util . * ; class GFG { static int maxORminusXOR ( int N ) { int MSB = ( int ) Math . ceil ( Math . log ( N ) ) ; int M = 0 ; for ( int i = 0 ; i <= MSB ; i ++ ) M += ( 1 << i ) ; return M ; } public static void main ( String [ ] args ) { int N = 10 ; System . out . print ( maxORminusXOR ( N ) ) ; } }