hackerrank-solutions/algorithms/bit-manipulation/maximizing-xor/maxXor.cpp

22 lines
259 B
C++

#include <iostream>
#include <stdint.h>
using namespace std;
int main()
{
uint32_t L, R, M;
cin >> L >> R;
M = L^R;
M--;
M |= M >> 1;
M |= M >> 2;
M |= M >> 4;
M |= M >> 8;
M |= M >> 16;
cout << M;
return 0;
}