fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. long long rightRotate(long long n, unsigned int d)
  4. {
  5. /* In n>>d, first d bits are 0.
  6. To put last 3 bits of at
  7. first, do bitwise or of n>>d
  8. with n <<(INT_BITS - d) */
  9. int v=log2(n);
  10. return (n >> d)|(n << (64 - d));
  11. }
  12. int countZeros(long long x)
  13. {
  14. // Keep shifting x by one until leftmost bit
  15. // does not become 1.
  16. int total_bits = sizeof(x) * 8;
  17. int res = 0;
  18. while ( !(x & (1 << (total_bits - 1))) )
  19. {
  20. x = (x << 1);
  21. res++;
  22. }
  23.  
  24. return res;
  25. }
  26.  
  27. long long leftRotate(long long n, unsigned int d)
  28. {
  29.  
  30. /* In n<<d, last d bits are 0. To
  31. put first 3 bits of n at
  32. last, do bitwise or of n<<d
  33. with n >>(INT_BITS - d) */
  34. return (n << d)|(n >> (64 - d));
  35. }
  36. int main() {
  37. long long a=576460752303423488;
  38. cout<<a<<" ";
  39. a=leftRotate(a,1);
  40. // cout << countZeros(a);
  41. cout<<a;
  42. return 0;
  43. }
Success #stdin #stdout 0s 4404KB
stdin
Standard input is empty
stdout
576460752303423488 1152921504606846976