Advertisement
jayati

Rotate Bits

Oct 2nd, 2023
738
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. //{ Driver Code Starts
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4.  
  5. // } Driver Code Ends
  6. class Solution
  7. {
  8.   public:
  9.         vector <int> rotate (int n, int d)
  10.         {
  11.            
  12.              d%=16;
  13.  
  14.    
  15.         int left = ((n<<d) | (n>>(16-d))) & 65535;
  16.    
  17.      
  18.         int right = (n>>d) | (n<<(16-d)) & 0xFFFF;
  19.  
  20.    
  21.     return {left,right};
  22.         }
  23. };
  24.  
  25. //{ Driver Code Starts.
  26. int main()
  27. {
  28.     int t; cin >> t;
  29.     while (t--)
  30.     {
  31.        
  32.         int n, d; cin >> n >> d;
  33.         Solution ob;
  34.         vector <int> res = ob.rotate (n, d);
  35.         cout << res[0] << endl << res[1] << endl;
  36.     }
  37. }
  38. // Contributed By: Pranay Bansal
  39.  
  40. // } Driver Code Ends
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement