Reverse bits of a given 32 bits unsigned integer.

For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as00111001011110000010100101000000).

Follow up:
If this function is called many times, how would you optimize it?

Related problem: Reverse Integer

Credits:
Special thanks to @ts for adding this problem and creating all test cases.

Hide Tags

Bit Manipulation

 

  遍历输入数的位,输出数反向添加,循环时候需要注意先移位后修改,反过来会错的。
 
#include<iostream>
using namespace std; class Solution {
public:
uint32_t reverseBits(uint32_t n) {
uint32_t m=;
for(int i=;i<;i++){
m<<=;
m = m|(n & );
n>>=;
}
return m;
}
}; int main()
{
uint32_t n = ;
Solution sol;
cout<<sol.reverseBits(n)<<endl;
return ;
}

[LeetCode] Reverse Bits 位操作的更多相关文章

  1. 2016.5.16——leetcode:Reverse Bits(超详细讲解)

    leetcode:Reverse Bits 本题目收获 移位(<<  >>), 或(|),与(&)计算的妙用 题目: Reverse bits of a given 3 ...

  2. [LeetCode] Reverse Bits 翻转位

    Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in ...

  3. [leetcode] Reverse Bits

    Reverse Bits Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (re ...

  4. leetcode reverse bits python

    Reverse Bits Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (re ...

  5. LeetCode Reverse Bits 反置位值

    题意:给定一个无符号32位整数,将其二进制形式左右反置,再以整型返回. 思路:循环32轮,将n往右挤出一位就补到ans的尾巴上. class Solution { public: uint32_t r ...

  6. lc面试准备:Reverse Bits

    1 题目 Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represente ...

  7. [LeetCode] 190. Reverse Bits 颠倒二进制位

    Reverse bits of a given 32 bits unsigned integer. Example 1: Input: 00000010100101000001111010011100 ...

  8. [LeetCode] 190. Reverse Bits 翻转二进制位

    Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in ...

  9. 【LeetCode】190. Reverse Bits

    题目: Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented ...

随机推荐

  1. base64转图片上传

    不成功,但是有一定的借鉴性 /** * @param base64Codes * 图片的base64编码 */ function sumitImageFile(base64Codes){ consol ...

  2. phpstudy iis版本 php4.4.5 和 php5.6.7目录权限问题

    开始用的php4.4.5  +iis 权限设置好了,切换成php5.6.7后目录没有了写入权限,各种百度后未能解决 php4.4.5  +iis  时 iis 匿名身份验证 用户是 IUSR    目 ...

  3. String java问题随笔

    1.字符串加密 设计思想: 每个字符都能够转化为整数型,也能将整数型转化为字符类型,这样我们在加密时候由于向后推3个,所以可以将字符转换为整形,然后加3,之后在将运算完的变量转化为字符后输出,就可以实 ...

  4. WIFI共享大师无法开启发射功能

    1.打开服务(ctrl+R)输入services.msc 2.将关于wifi的服务打开 这里有windows移动热点服务和WLAN开头的服务

  5. Django2.2使用mysql数据库pymysql版本不匹配问题的解决过程与总结

    前置条件 django版本:2.2.1 python版本:3.6.6 mysql版本:mysql-community8.0.15 问题 在搭建django项目,配置mysql数据库时遇到无法迁移数据库 ...

  6. BFS:HDU2597-Dating with girls(2) (分时间标记状态)

    Dating with girls(2) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  7. 自己用C语言写RH850 F1KM serial bootloader

    了解更多关于bootloader 的C语言实现,请加我QQ: 1273623966 (验证信息请填 bootloader),欢迎咨询或定制bootloader(在线升级程序). 手上有块Renesas ...

  8. vs code 快捷键总结

    返回上个光标:alt + ←列编辑模式:shift + alt + 鼠标左键

  9. 【Clone Graph】cpp

    题目: Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. ...

  10. MOCTF-火眼金睛

    MOCTF-火眼金睛 http://119.23.73.3:5001/web10/ 把这个题目当作python爬虫来练习. 首先要获取到文本框里面的全部信息, import requests impo ...