Leetcode 190 Reverse Bits 位运算

反转二进制

 1 class Solution {
 2 public:
 3     uint32_t reverseBits(uint32_t n) {
 4         uint32_t ans = 0;
 5         for (int  i = 0; i<32; ++i,n >>=1){
 6             ans = (ans<< 1)|(n & 1);
 7         }
 8         return ans;
 9     }
10 };

 

posted @ 2016-03-12 22:43  Breeze0806  阅读(109)  评论(0编辑  收藏  举报