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).

注意应该做到平台无关性,需要做到这样的话应该声明一个uint32量然后一直向左移,知道得到 0 就可以得到uint32的位数大小 :

 class Solution {
public:
uint32_t reverseBits(uint32_t n) {
uint32_t result = ;
for(uint32_t i = ; i != ; i <<= ){
result <<= ;
result |= (n & );
n >>= ;
}
return result;
}
};

LeetCode OJ:Reverse Bits(旋转bit位)的更多相关文章

  1. LeetCode 190. Reverse Bits (反转位)

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

  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. leetcode:Reverse Bits

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

  5. 【leetcode】Reverse Bits(middle)

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

  6. Java for LeetCode 190 Reverse Bits

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

  7. Leetcode 190. Reverse Bits(反转比特数)

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

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

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

  9. Leetcode 190 Reverse Bits 位运算

    反转二进制 class Solution { public: uint32_t reverseBits(uint32_t n) { uint32_t ans = ; ; i<; ++i,n &g ...

  10. Java [Leetcode 190]Reverse Bits

    题目描述: everse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represente ...

随机推荐

  1. Ubuntu16.04安装MySQLdb

    buntu 系统下进行的操作 首先安装了pip工具 1 sudo apt-get install python-pip 然后使用 1 sudo pip install mysql-python   安 ...

  2. 使用react常见的坑

    触摸事件 React中的触摸事件仅用三种,touchstart, touchend, touchend,可是这种会有问题,有时候我需要滚动页面的时候,很容易触发某一个元素的touchend事件,为此笔 ...

  3. Linux下mysql允许远程连接怎么设置

    1.root用户登录到mysql数据库代码示例:/usr/local/mysql/bin/mysql -u root -p (输入密码进入mysql)2.进入mysql,输入:代码示例:use mys ...

  4. [NOI2014]动物园(kmp)

    题目 https://www.luogu.org/problemnew/show/P2375 做法 查找多少个前缀与后缀配对,其实就是\(fail\)树的深度 而不可重叠,其实\(i\)不可用的,\( ...

  5. NOIP2019前的训练记录

    \(April\):肛多项式,学\(FWT\)一个小时无果后背了六个公式,看来证明又得咕很久了

  6. python error: curl: (1) Protocol "'https" not supported or disabled in libcurl

    python 调用curl访问一个网页时,出现error: curl: (1) Protocol "'https" not supported or disabled in lib ...

  7. 使用ThinkPHP5连接数据库

    1.在application的database.php中设置数据库信息. return [ // 数据库类型 'type' => 'mysql', // 服务器地址 'hostname' =&g ...

  8. JSON 中JsonConfig的使用(转)

    我们通常对一个Json串和Java对象进行互转时,经常会有选择性的过滤掉一些属性值,而json-lib包中的JsonConfig为我们提供了这种 功能,具体实现方法有以下几种.(1)建立JsonCon ...

  9. Swift学习笔记 - Swift属性只读

    在OC中我们经常用到只读属性,用readonly修饰一下就行了,但在Swift中已经不是这样修饰的了,下面记录一下Swift中只读属性的使用 在OC中的只读: //只读属性 @property(rea ...

  10. MySQL MERGE存储引擎 简介及用法

    MERGE存储引擎把一组MyISAM数据表当做一个逻辑单元来对待,让我们可以同时对他们进行查询.构成一个MERGE数据表结构的各成员MyISAM数据表必须具有完全一样的结构.每一个成员数据表的数据列必 ...