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. Ip 地址

    访问 ip.mayfirst.org可以显示你的ip地址,如果你可以联网的话.

  2. common.css

    /* global */ document,body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,p,blockqu ...

  3. Maven更新父子模块的版本号

    前置条件: 1.安装有吃饭的家伙JAVA和MAVEN. 首先,需要有一个packaging类型为pom的pom.xml文件即我们的parent项目pom文件.在这个parent项目中配置好groupI ...

  4. 【weka应用技术与实践】过滤器

    weka中的过滤器主要用于数据预处理阶段对数据集的各种操作. 今天简单地使用一下过滤器: 首先打开一个自带数据集weather.numeric.arff,这是一个关于通过天气条件,气温以及风力等因素来 ...

  5. SQLServer的数据类型

    第一大类:整数数据 bit:bit数据类型代表0,1或NULL,就是表示true,false.占用1byte.int:以4个字节来存储正负数.可存储范围为:-2^31至2^31-1.smallint: ...

  6. Java Web学习系列——创建基于Maven的Web项目

    创建Maven Web项目 在MyEclipse for Spring中新建Maven项目 选择项目类型,在Artifact Id中选择maven-archetype-webapp 输入Group I ...

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

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

  8. 关于在for循环中绑定事件打印变量i是最后一次。

    其实函数引用的外部变量都是最后一次的值. <!DOCTYPE html> <html lang="en"> <head> <meta ch ...

  9. ruby -- 进阶学习(十)自定义路由中:new, :collection和:member的区别

    学习链接:http://rubyer.me/blog/583/ RESTful风格的路由动词默认有7个(分别为:index, show, create, new, edit, update, dest ...

  10. Web离线存储的几种方式

    随着HTML5的正式定稿,我们也可以大量使用HTML离线网络应用程序的特性. #1.Application Cache Application Cache 可以很简单让我们的WebApp具有离线的能力 ...