【leetcode】【190】Reverse Bits

#include<iostream>
#include<stdint.h>
using namespace std;

class Solution {
public:
	uint32_t reverseBits(uint32_t n) {
		uint32_t sum = 0;
		uint32_t mask = 1;
		int count = 32;
		while (count>0){
			uint32_t temp = (n&mask); //获取最低位
			sum = (sum << 1) + temp; //反转
			n >>= 1; 
			--count;
		}
		return sum;
	}
};

int main(){
	Solution solution;
	cout << solution.reverseBits(43261596) << endl;

	system("pause");
	return 0;
}

posted on 2015-05-09 11:16  ruan875417  阅读(115)  评论(0编辑  收藏  举报

导航