Advertisement
Kali_prasad

Untitled

Mar 7th, 2022
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     uint32_t reverseBits(uint32_t n) {
  4.         uint32_t k=0;
  5.         uint32_t a=1;
  6.        
  7.         for(int i=0;i<=31;i++){
  8.             if((n&a)==0)/* we can also use if(n%2==0)*/
  9.                 k=k<<1;
  10.             else
  11.             {
  12.                 k=k<<1;
  13.                 k=k|1;
  14.             }
  15.             n=n>>1;
  16.          }
  17.         return k;
  18.        
  19.        
  20.     }
  21. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement