Find a value whose XOR with given number is maximum | Java implementation of the above approach ; Function To Calculate Answer ; Find number of bits in the given integer ; XOR the given integer with poe ( 2 , number_of_bits - 1 and print the result ; Driver Code
import java . io . * ; class GFG { static int calculate ( int X ) { int number_of_bits = 8 ; return ( ( 1 << number_of_bits ) - 1 ) ^ X ; } public static void main ( String [ ] args ) { int X = 4 ; System . out . println ( " Required ▁ Number ▁ is ▁ : ▁ " + calculate ( X ) ) ; } }