LeetCode题解之Reverse Bits

1、题目描述

2、题目分析

使用bitset 类的方法

3、代码

 1 uint32_t reverseBits(uint32_t n) {
 2         bitset<32> b(n);
 3         
 4         string b_s = b.to_string() ;
 5         
 6         for( string::iterator it_b = b_s.begin() , it_e = b_s.end() - 1;  it_b < it_e ; ++it_b ,--it_e ){
 7             swap(*it_b ,*it_e);
 8         }
 9         
10         bitset<32> br( b_s ) ;
11         
12         uint32_t nr = (uint32_t) br.to_ulong() ;
13         return nr;
14         
15         
16         
17     }
pp
原文地址:https://www.cnblogs.com/wangxiaoyong/p/9295806.html