首页 > 其他 > 详细

190. Reverse Bits

时间:2020-05-10 21:01:21      阅读:47      评论:0      收藏:0      [点我收藏+]

技术分享图片

 

 

#include<iostream>
#include<string>
using namespace std;
uint32_t reverseBits(uint32_t n) {
    uint32_t a = 0;
    int count = 0;
    string s = "";
    while (n) {
        s += to_string(n%2);
        n = n / 2;
    }
    for (int i = 0; i < s.length(); i++) {
        a = a * 2 + int(s[i] - 0);
    }
    count = 32 - s.length();
    while (count) {
        a = a * 2;
        count -= 1;
    }
    return a;
}

int main() {
    uint32_t a = 4294967293;
    cout << reverseBits(a) << endl;
    return 0;
}

 

190. Reverse Bits

原文:https://www.cnblogs.com/luo-c/p/12864737.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!