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 ...
随机推荐
- P2573 [SCOI2012]滑雪
题目描述 a180285非常喜欢滑雪.他来到一座雪山,这里分布着 M 条供滑行的轨道和 N 个轨道之间的交点(同时也是景点),而且每个景点都有一编号 i ( 1≤i≤N )和一高度 Hi.a18028 ...
- 【转】实现虚拟机VMware上linux与windows互相复制与粘贴
1.点击虚拟机-->安装vm tool 2.完成后在系统桌面会出现一个tar文件,解压到tmp目录 下 3.终端cd到该文件夹下,执行./vmware-install.pl 一路回车到底.4.重 ...
- 【NOI2006】聪明的导游
[NOI2006]聪明的导游 题面 洛谷 题目描述 小佳最近迷上了导游这个工作,一天到晚想着带游客参观各处的景点.正好 M 市在举行 NOI,来参观的人特别的多.不少朋友给小佳介绍了需要导游的人. M ...
- windows2016上如何通过攻击ETERNALBLUE获得meterpreter反弹
windows2016上如何通过攻击ETERNALBLUE获得meterpreter反弹 译:by backlion 0x00前言 当微软发布MS17-010漏洞的补丁时,该漏洞影响的范围是从Win ...
- SpringBoot web 小项目
Spring Boot 整合 Thymeleaf 完整 Web 案例 原创出处 作者:泥瓦匠BYSocket 希望转载,保留摘要,谢谢! Thymeleaf 是一种模板语言.那模板语言或模板引擎是什 ...
- 【bzoj2893】征服王
Portal -->bzoj2893 Descripiton 给你一个\(n\)个点\(m\)条边的有向图,有一些点是起始点,有一些点是终止点,一次操作可以从一个起始点开始沿着有向图的边走到一个 ...
- C++堆和栈详解(转)
一.预备知识—程序的内存分配 一个由C/C++编译的程序占用的内存分为以下几个部分 1.栈区(stack)— 由编译器自动分配释放 ,存放函数的参数值,局部变量的值等.其 操 ...
- 流媒体协议之RTP详解20170921
1.RTP介绍 实时传输协议RTP(Real-time Transport Protocol)是一个网络传输协议,它是由IETF的多媒体传输工作小组1996年在RFC 1889中公布的,后在RFC35 ...
- jsp 的 3 个编译指令
JSP 的编译指令是通知 JSP 引擎的消息,它不直接生成输出. 常见的编译指令有如下三个: 1.page:该指令是针对当前页面的指令 2.include:用于指定包含另一个页面 3.taglib:用 ...
- python编码问题FAQ
http://note.youdao.com/noteshare?id=2cfb0ac4da042c2550aa3918beda81ec