Smallest pair of integers with minimum difference whose Bitwise XOR is N | Java program for the above approach ; Function to find the numbers A and B whose Bitwise XOR is N and the difference between them is minimum ; Find the MSB of the N ; Find the value of B ; Find the value of A ; Print the result ; Driver Code
public class MyClass { static void findAandB ( int N ) { int K = ( int ) ( Math . log ( N ) / Math . log ( 2 ) ) ; int B = ( 1 << K ) ; int A = B ^ N ; System . out . println ( A + " ▁ " + B ) ; } public static void main ( String args [ ] ) { int N = 26 ; findAandB ( N ) ; } }