Reverse bits of a given 32 bits unsigned integer.

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

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

class Solution {
public:
uint32_t reverseBits(uint32_t n) {
uint32_t ret = ; //NOTE: integer got from this way should be decalred as unsigned
int tmp;
/*把一个unsigned int 数字1一直左移,直到它变成全0的时候,也就得到了该机器内unsigned int的长度*/
for (i = ; i != ; i <<= )
tmp = n & 0x1;
n >>= ;
ret <<= ; //must before the operation |
ret |= tmp;
}
return ret;
}
};

190. Reverse Bits (Int; Bit)的更多相关文章

  1. LeetCode 190. Reverse Bits (算32次即可)

    题目: 190. Reverse Bits Reverse bits of a given 32 bits unsigned integer. For example, given input 432 ...

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

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

  3. LeetCode 【190. Reverse Bits】

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

  4. Java for LeetCode 190 Reverse Bits

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

  5. 190. Reverse Bits -- 按位反转

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

  6. 190. Reverse Bits

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

  7. 【LeetCode】190. Reverse Bits

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

  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

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 我的个人博客已创建,欢迎大家持续关注! 一天一道le ...

随机推荐

  1. GridView Bind 短日期 格式

    ASP.NET的GridView控件的编辑模板中,需要绑定数据库中的某个字段,如<%# Bind("startTime","{0:d}") %> 在 ...

  2. Firefox What's New 太难找了

    Firefox每次更新版本,不知道更新了什么,找不到Waht‘s New,做个记录! 1.点击mozilla下拉 2.最左侧 MOZILLA>SUPPORT>Firefox 3.https ...

  3. ---github git clone 加速

    https://www.zhihu.com/question/27159393/answer/35528173 git config --global http.postBuffer 52428800 ...

  4. VirtualBox配置

    安装增强工具:http://mikemainguy.blogspot.jp/2015/03/installing-virtualbox-guest-additions.html 安装ssh:https ...

  5. WDA-5-VIEW视图切换

    这一部分介绍同一窗口下不同视图之间的链接跳转. 前提:完成上一步骤MAIN视图ALV显示. 1.效果展示 点击ALV物料下划线链接,页面跳转到物料明细页面. 2.实现过程 基于上一步骤在MAIN页面显 ...

  6. opencv-3.3安装记录-ubuntu 14.04

    这个二逼问题不会是最后一次. ipcv-****.tar.gz 这个文件在cmake的时候会卡住,这里先下载这个文件,大概38M,放到.cache/ippcv目录下就可以了.貌似还需要改下名字. 就可 ...

  7. linux shell 杂

    1. 字符串截取 var=http://www.baidu.com/index.html echo ${var} var=http://www.baidu.com/index.html /*从左到右第 ...

  8. 如何做Go的性能优化?(转)

    Go的性能优化其实总的来说和C/C++等这些都差不多,但也有它自己独有的排查方法和陷阱,这些都来源于它的语言特性和环境. 1.性能优化前提——任何好的东西都是在正确的前提上 代码界的很多事是和我们生活 ...

  9. Java IO中转换流的作用

    在<Java网络编程>中,有这样一段话: ”Reader和Writer最重要的子类是InputStreamReader和OutputStreamWriter类. InputStreamRe ...

  10. C++ new 和malloc 区别

    1.分配地方不同,malloc是堆上面,new是自由存储区域 2.malloc/delete是函数,new/delete是操作符,可以重载 3.malloc 要指定大小,返回的是void*指针,开辟的 ...