maximizing-xor: c++ implementation
This commit is contained in:
parent
1bac478cb3
commit
eedc533521
2 changed files with 23 additions and 0 deletions
22
algorithms/bit-manipulation/maximizing-xor/maxXor.cpp
Normal file
22
algorithms/bit-manipulation/maximizing-xor/maxXor.cpp
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue