Reverse Bits-位反转
来源:互联网 发布:58端口多少钱一个月 编辑:程序博客网 时间:2024/05/16 06:03
- 题目描述
- 知识点及思路
- 总结
一.题目描述
简述:求一个数的二进制并求反
二.知识点及思路
知识点:移位;与或运算
思路:①(n&temp)>>i保证每次将原位置位移动至最低位②temp<<1保证与指定位做运算操作③value<<1保证了最低位移动至最高位④ value=(value<<1)|((n&temp)>>i)相当于位求和运算
代码如下:
class Solution {public: uint32_t reverseBits(uint32_t n) { uint32_t value = 0; uint32_t temp=1; for (uint32_t i = 0; i < 32; ++i) { value=(value<<1)|((n&temp)>>i); temp=temp<<1; } return value; }};
三.总结
I.移位操作细节需多积累II.让我们一同努力,明天会更好!
0 0
- Reverse Bits-位反转
- [LeetCode-190] Reverse Bits(反转位)
- Reverse Bits 二进制数反转 比较多的位运算符的使用
- (*leetcode_位运算)Reverse Bits
- 字节的按位逆序 Reverse Bits
- Reverse Bits(数的位倒置)
- 位运算——Reverse Bits
- LeetCode 190 Reverse Bits (位运算 推荐)
- leetcode-190 reverse bits 位运算
- 位操作 leetcode-190. Reverse Bits
- Leetcode#190. Reverse Bits (反向位&位运算)
- 反转整数的每一位(reverse integer)
- leetcode_190. Reverse Bits 比特流反转,求十进制数的32位二进制串翻转后对应的十进制数,二进制与十进制转换
- 位处理:191. Number of 1 Bits&&190. Reverse Bits&&7. Reverse Integer
- Reverse Bits
- Reverse Bits
- Reverse Bits
- Reverse Bits
- 利用 Bootstrap 进行快速 Web 开发
- 3种PHP连接MYSQL数据库的常用方法
- 设置npm安装程序时的默认目录
- 1003. Emergency (25)
- Android基础——TabHost使用(自定义按钮菜单)
- Reverse Bits-位反转
- 数论 随记
- 配分函数
- 【tyvj 1860】 后缀数组模板
- 深拷贝与浅拷贝
- LAMPSecurity渗透演练
- Python字符串操作
- leetcode171.[math] Excel Sheet Column Number
- Hdu 5016 Baby Ming and Matrix games【dfs】