题目要求:

颠倒给定的 32 位无符号整数的二进制位。

示例:

输入: 00000010100101000001111010011100

输出: 00111001011110000010100101000000

解释: 输入的二进制串 00000010100101000001111010011100 表示无符号整数 43261596,

因此返回 964176192,其二进制表示形式为 00111001011110000010100101000000。

代码:

class Solution {
public:
uint32_t reverseBits(uint32_t n) {
uint32_t result = 0;
for(int i = 0; i < 32; i++) {
result <<= 1;
result = result | (n & 1);
n >>= 1;
}
return result;
}
};

分析:

会对二进制数末尾进行赋值

LeetCode. 颠倒二进制位的更多相关文章

  1. 【python】Leetcode每日一题-颠倒二进制位

    [python]Leetcode每日一题-颠倒二进制位 [题目描述] 颠倒给定的 32 位无符号整数的二进制位. 示例1: 输入: 00000010100101000001111010011100 输 ...

  2. Java实现 LeetCode 190 颠倒二进制位

    190. 颠倒二进制位 颠倒给定的 32 位无符号整数的二进制位. 示例 1: 输入: 00000010100101000001111010011100 输出: 0011100101111000001 ...

  3. Leetcode 190.颠倒二进制位 By Python

    颠倒给定的 32 位无符号整数的二进制位. 示例: 输入: 43261596 输出: 964176192 解释: 43261596 的二进制表示形式为 000000101001010000011110 ...

  4. 【leetcode 简单】第四十九题 颠倒二进制位

    颠倒给定的 32 位无符号整数的二进制位. 示例: 输入: 43261596 输出: 964176192 解释: 43261596 的二进制表示形式为 000000101001010000011110 ...

  5. 力扣(LeetCode)颠倒二进制位 个人题解

    颠倒给定的 32 位无符号整数的二进制位. 示例 1: 输入: 00000010100101000001111010011100 输出: 0011100101111000001010010100000 ...

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

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

  7. leetcode 190. 颠倒二进制位(c++)

    颠倒给定的 32 位无符号整数的二进制位. 示例 1: 输入: 00000010100101000001111010011100输出: 00111001011110000010100101000000 ...

  8. LeetCode刷题2——颠倒二进制位

    一.题目要求 二.题目背景 此题依旧属于位运算范畴 知识点1:有符号和无符号二进制是怎样表现的? 对于有符号数,最高位为1说明是个负数 知识点2:进制之间的相互转换 (1)十进制转十六进制 hex(n ...

  9. [Swift]LeetCode190. 颠倒二进制位 | Reverse Bits

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

随机推荐

  1. CF1174D Ehab and the Expected XOR Problem(二进制)

    做法 求出答案序列的异或前缀和\(sum_i\),\([l,r]\)子段异或和可表示为\(sum_r\bigoplus sum_{l-1}\) 故转换问题为,填\(sum\)数组,数组内的元素不为\( ...

  2. Linux MySQL 储存中文失败简单解决办法

    如图,保存的中文都变成了??? show create table table_name;可以查到表的默认编码 这里看到默认的字符集是latin1,而不是utf8 需要修改 alter databas ...

  3. springMVC_配置文件搭建基础环境

    SpringMVC与Struts的区别. 一.基础jar包 二.①DispatcherServlet,handelMapping,webAction(colltroller),ModelAndView ...

  4. 关于long_query_time的设置,可不可以说是mysql的一个小小bug呢

    我们知道对对于MySQL的日志功能,我们可以完全自己控制到底写还是不写.一般来说,binlog我们一般会开启,而对于慢查询我们一般会在开发的时候调试和观察SQL语句的执行速度.但今天发现一个问题.在使 ...

  5. 使用 Fiddler 抓取iPhone 的 HTTPS 请求

    Fiddler 是著名的 HTTP(S) 抓包工具,功能十分强悍.Fiddler 采用代理的方式进行抓包,所以使用范围就非常广泛,不仅可以在 PC 端使用,更可以在移动设备上使用. 要在 iPhone ...

  6. selinux 开启和关闭

    对于新手来说,linux的selinux困扰了一大批学员,开启后,导致文件权限修改不了等问题,下面就是关闭设置setlinux的方法 查看SELinux状态: 1./usr/sbin/sestatus ...

  7. windows7 10 windows2008 windws2012 nfs客户端的安装

    servermanagercmd.exe -install FS-NFS-Services   for windows2008 windows2012 在添加功能角色-添加文件打印服务选择nfs客户端 ...

  8. error: cannot connect to daemon解决办法

    本文链接:https://blog.csdn.net/ipinki1218/article/details/80704806运行adb shell时出现error: cannot connect to ...

  9. Somatic hypermutation (or SHM) is a cellular mechanism by which the immune system adapts to the new foreign elements that confront it (e.g. microbes), as seen during class switching. Somatic hypermut

    Somatic hypermutation (or SHM) is a cellular mechanism by which the immune system adapts to the new ...

  10. ijkplayer相关

    直播技术总结(二)ijkplayer的编译到Android平台并测试解码库 https://blog.csdn.net/hejjunlin/article/details/55670380