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. 白鹭引擎 - 显示对象与 HelloWord ( 绘制了一个红蓝相间的 2 x 2 格子 )

    1: 白鹭引擎默认实在一个 640 * 1136 的画布上作画 2: 入口文件 Main.ts,  类 Main 是程序的入口 // 1, 在一个宽高为 640 * 1136 的画布上作画 // 2, ...

  2. HTML5 Canvas 小例子 旋转的时钟

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  3. Valgrind简单用法 (转)

    转自 http://www.cnblogs.com/sunyubo/archive/2010/05/05/2282170.html Valgrind的主要作者Julian Seward刚获得了今年的G ...

  4. beego orm操蛋问题:操作都需要主键

    查看bee generate appcode自动生成的代码,会发现orm操作都是以主键为依据的. 如果我不想根据主键怎么操作?用 ORM.Raw(cmd).Exec()吧,cmd=[你的mysql语句 ...

  5. APP-11-视觉技术-通用文字识别

    1.Postman测试 2.参数 https://cloud.baidu.com/doc/OCR/OCR-API.html#.EC.DF.48.27.9B.69.A4.2C.54.1B.DC.95.6 ...

  6. jquery接触初级----jquery 选择器

    css 选择器主要有:元素选择器,ID选择器,类选择器,群组选择器,后代选择器,普通配符选择器等,通过css选择,我们可以很方便的给元素添加样式,使网页看起来更加好看 jquery 选择器也有相似的功 ...

  7. PropertiesUtil

    PropertiesUtil package com.zjx.util; import java.io.IOException; import java.io.InputStream; import ...

  8. linux目录结构详解(以suse linux 10为例)

    一.文件系统结构 位于Linux系统的最顶端即根目录是/.Linux的文件系统的入口就是/,所有的目录.文件.设备都在/之下,/就是Linux文件系统的组织者,也是最上级的领导者. 它之下的子目录有: ...

  9. HTML框架、列表、表格

    本章内容一.列表1.有序列表ol <ol> <li></li> </ol>type的值有3个 默认为1(阿拉伯数字), 还有A/a(大小写字母),I/i ...

  10. ubuntu 下安装和启动SSH 服务

    安装OPENSSH 服务端 sudo apt-get install openssh-server 查看进程是否启动 ps -e | grep ssh 删除密钥文件 rm /etc/ssh/ssh_h ...