Maximizing XOR

main()
{
    int L=14; /* Lower Limit */
    int R=19; /* Upper Limit */

    int x=1;
    int P;
  
    P = L^R;
  
    while(P)
    {
        x = x<<1;
        P = P>>1;
    }
  
    x = x-1;
  
    printf("%d\n",x);
}

------------------------------------------------

Find 2 numbers X and Y's XOR value which are existing between 2 give numbers L and R, ( L<=X<=Y<=R ), such that  X (XOR) Y is maximum.

You have to find the maximum XOR value possible.

No comments:

Post a Comment