LeetCode题解之Reverse Bits

时间:2023-03-10 00:03:48
LeetCode题解之Reverse Bits

1、题目描述

LeetCode题解之Reverse Bits

2、题目分析

使用bitset 类的方法

3、代码

 uint32_t reverseBits(uint32_t n) {
bitset<> b(n); string b_s = b.to_string() ; for( string::iterator it_b = b_s.begin() , it_e = b_s.end() - ; it_b < it_e ; ++it_b ,--it_e ){
swap(*it_b ,*it_e);
} bitset<> br( b_s ) ; uint32_t nr = (uint32_t) br.to_ulong() ;
return nr; }