fork(4) download
  1. #include <iostream>
  2. #include <bitset>
  3. using namespace std;
  4.  
  5. typedef bitset<sizeof(unsigned) * 8> bitset_uint;
  6.  
  7. int main() {
  8. unsigned l, r;
  9. cin >> l >> r;
  10.  
  11. const unsigned x = sizeof(unsigned) * 8 - __builtin_clz( l ^ r ) - 1;
  12. const unsigned result = (l | 1 << x) & ~0 << x;
  13. const unsigned a = (l == r) ? l : result - 1;
  14. const unsigned b = (l == r) ? r : result;
  15.  
  16. cout << "l\t " << bitset_uint(l) << ' ' << l << endl;
  17. cout << "r\t " << bitset_uint(r) << ' ' << r << endl;
  18. cout << "a\t " << bitset_uint(a) << ' ' << a << endl;
  19. cout << "b\t " << bitset_uint(b) << ' ' << b << endl;
  20. cout << "xor\t " << bitset_uint(a ^ b) << ' ' << (a ^ b) << endl;
  21. return 0;
  22. }
Success #stdin #stdout 0s 3480KB
stdin
0 4
stdout
l	 00000000000000000000000000000000 0
r	 00000000000000000000000000000100 4
a	 00000000000000000000000000000011 3
b	 00000000000000000000000000000100 4
xor	 00000000000000000000000000000111 7