190.Reverse Bits---位运算
题目链接:https://leetcode.com/problems/reverse-bits/description/
题目大意:将数值的二进制反转。
法一(借鉴):由于是无符号32位整型,当二进制反转后会得到一个32位的整型,eclipse中已经无法正常显示了,但是转为二进制还是正确的。至于为什么我也不知道。代码如下(耗时2ms):
public int reverseBits(int n) {
int res = 0;
for(int i = 0; i <= 31; i++) {
//1010->tmp=0,n=101,res=00,
int tmp = n & 1;//取最后一位
n = n >> 1;//右移
res = res<<1;//结果左移一位
res = res | tmp;//将最后一位加到结果左移的那个位上去,也就是最低位上
}
// System.out.println(Integer.toBinaryString(res));
//在eclipse里会显示错误,因为res已经移位形成了32位的数,已经无法正常显示了
//但是当转为二进制的时候是正常的
return res;
}
其他的解法:http://blog.csdn.net/feliciafay/article/details/44536827
190.Reverse Bits---位运算的更多相关文章
- Leetcode 190 Reverse Bits 位运算
反转二进制 class Solution { public: uint32_t reverseBits(uint32_t n) { uint32_t ans = ; ; i<; ++i,n &g ...
- LeetCode 190. Reverse Bits (算32次即可)
题目: 190. Reverse Bits Reverse bits of a given 32 bits unsigned integer. For example, given input 432 ...
- 190. Reverse Bits -- 按位反转
Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in ...
- 【LeetCode】190. Reverse Bits
题目: Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented ...
- [LeetCode] 190. Reverse Bits 颠倒二进制位
Reverse bits of a given 32 bits unsigned integer. Example 1: Input: 00000010100101000001111010011100 ...
- [LeetCode] 190. Reverse Bits 翻转二进制位
Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in ...
- 【LeetCode】190. Reverse Bits 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 解题方法 二进制字符串翻转 位运算 日期 题目地址:https://le ...
- 190. Reverse Bits
题目: Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented ...
- LeetCode 190. Reverse Bits (反转位)
Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in ...
- 【一天一道Leetcode】#190.Reverse Bits
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 我的个人博客已创建,欢迎大家持续关注! 一天一道le ...
随机推荐
- bzoj1211-树的计数
题意 给出 \(n\) 和长度为 \(n\) 的数列 \(d\) 表示每个点的度数,问有多少颗满足要求的树. 分析 这题是prufer编码的应用. prufer编码是对一个带标号无根树的刻画,生成方式 ...
- bzoj5123 [Lydsy12月赛]线段树的匹配
题意: 线段树是这样一种数据结构:根节点表示区间 [1, n]:对于任意一个表示区间 [l, r] 的节点,若 l < r, 则取 mid = ⌊l+r/2⌋,该节点的左儿子为 [l, mid] ...
- bzoj5127[Lydsy12月赛]数据校验
多少年不写题解了 题目描述: 著名出题人小 Q 出了一道题,这个题给定一个正整数序列 a1, a2, ..., an,并保证输入数据中,对于 a 的任意一个非空连续子区间 [l, r],该区间内出现过 ...
- 【Java】数据库查询的数据直接以指定文件类型下载到本地(弹出下载框)
欲实现的功能目标:当点击下图的导出数据文件时弹出文件下载框,默认csv格式,用户自定义下载的本地路径 遇到的问题: 1.项目之前做过一次下载,但是是使用了本地文件模板.用输入流读取文件模板,插入数据, ...
- BZOJ5071 小A的数字
设f[i]为选择i对i-1和i+1所带来的贡献.则有f[i-1]+f[i+1]+a[i]-2f[i]=b[i],特殊地,f[2]+a[1]=b[1],f[n-1]+a[n]-2f[n]=b[n].可以 ...
- MSF下ms17_010_psexec模块使用技巧
0x01 前言 MS17-010 的psexec是针对Microsoft Windows的两款最受欢迎的漏洞进行攻击. CVE-2017-0146(EternalChampion / EternalS ...
- Canny边缘检测原理及C#程序实现
http://blog.csdn.net/yjz_uestc/article/details/6664937 Canny边缘检测是被公认的检测效果最好的边缘检测方法,是由John F. Canny于1 ...
- spring mybatis 多数据源配置
1.创建好数据库的配置文件 mysql.url=jdbc:mysql://***/***?useUnicode=true&characterEncoding=UTF-8 mysql.usern ...
- 相机标定 和 单应性矩阵H
求解相机参数的过程就称之为相机标定. 1.相机模型中的四个平面坐标系: 1.1图像像素坐标系(u,v) 以像素为单位,是以图像的左上方为原点的图像坐标系: 1.2图像物理坐标系(也叫像平面坐标系)(x ...
- Nginx多个配置文件共用location配置
一.应用情况 很多时候我们在一台服务器上部署了不止 一个项目,我们通过Nginx来代理,为了方便管理往往会将各个项目的配置分开写到不同的配置文件中,如: 在nginx.conf 文件中加上 incl ...