Reverse Bits

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?

Related problem: Reverse Integer

Credits:
Special thanks to @ts for adding this problem and creating all test cases.
 
 class Solution
{
public:
uint32_t reverseBits(uint32_t n)
{
int A[] = {};
int i = ;
while(n > )
{
A[i++] = n % ;
n /= ;
} int sum = ;
for(i = ; i < ; i++)
sum = sum * + A[i]; return sum;
}
};

[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 python

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

  4. LeetCode Reverse Bits 反置位值

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

  5. [LeetCode] Reverse Bits 位操作

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

  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. For example, given input 43261596 (represented in ...

  8. 【一天一道Leetcode】#190.Reverse Bits

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

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

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

随机推荐

  1. BI项目需求分析书-模板

    目录 目录 .............................................................................................. ...

  2. main函数读取jar包外部的配置文件properties

    首先,Java的main方法有个初始化入参args,如下所示: public static void main(String[] args) {} 然后,在linux下执行jar包引入外部配置文件的命 ...

  3. 使用tomcat作为web应用容器时,启用新线程找不到Session的问题

    今天做一个功能,为了快速响应前端,业务完成后,另起了一个线程做一些不影响业务的统计工作,然后立即将业务操作结果返回给前台. 结果在新线程里报空指针找不到request对象.检查了下,我们用的是stru ...

  4. 斜堆(三)之 Java的实现

    概要 前面分别通过C和C++实现了斜堆,本章给出斜堆的Java版本.还是那句老话,三种实现的原理一样,择其一了解即可. 目录1. 斜堆的介绍2. 斜堆的基本操作3. 斜堆的Java实现(完整源码)4. ...

  5. 对于大于8046 bytes的行,RCSI/SI事务隔离级别无效

    自SQL Server 2005起,我们有了READ COMMITTED SNAPSHOT ISOLATION level (RCSI) 和SNAPSHOT ISOLATION level (SI)两 ...

  6. Win10 + VS2015 下编译 Qt5.6.0

    近期由于另外一个项目需要用 vs2015 ,于是把 Qt 也升级到了 5.6.0 .由于项目需要兼容 Windows xp ,所以需要自己编译 Qt .这里大致整理一下编译的过程. 安装 Active ...

  7. mysql-5.6.14-winx64免安装配置

    MySQL5.6.11安装步骤(Windows7 64位) 1. 下载MySQL Community Server 5.6.14 2. 解压MySQL压缩包 将以下载的MySQL压缩包解压到自定义目录 ...

  8. Python+Selenium进行UI自动化测试项目中,常用的小技巧2:读取配置文件(configparser,.ini文件)

    在自动化测试项目中,可能会碰到一些经常使用的但 很少变化的配置信息,下面就来介绍使用configparser来读取配置信息config.ini 读取的信息(config.ini)如下: [config ...

  9. [C#高级编程].NET体系结构

    本章内容: 编译和运行面向 .NET的代码 MSIL的优点 值类型和引用类型 数据类型化 理解错误处理和特性 程序集..NET基类和命名空间 本章主要介绍一些概念,内容不多. C#是专门为Micros ...

  10. ASP.NET 运行时详解 揭开请求过程神秘面纱

    对于ASP.NET开发,排在前五的话题离不开请求生命周期.像什么Cache.身份认证.Role管理.Routing映射,微软到底在请求过程中干了哪些隐秘的事,现在是时候揭晓了.抛开乌云见晴天,接下来就 ...