week7
来源:互联网 发布:货运物流软件 编辑:程序博客网 时间:2024/06/06 08:38
190. 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 as00111001011110000010100101000000).
分析:输入一个数字,输出其二进制反向后的数字。最简单的方法是建立一个32位数字0,每次向左平移一位后与原数字的对应位置取或。为了取到原数字的那一位,需要用一个平移后的1与原数字取与。
代码:
class Solution {
public:
uint32_t reverseBits(uint32_t n) {
uint32_t res = 0;
uint32_t temp = 1;
for (int i = 0; i < 32; i++) {
res = (res<<1 )|((n&temp)>>i);
temp= temp<<1;
}
return res;
}
};
网上还有一种看起来很像加密技术的做法,我还在学习……
阅读全文
0 0
- week7
- week7
- week7
- week7
- week7
- Leetcode Week7
- leetcode week7
- Algorithm-week7
- WEEK7 JAVA
- WEEK7 -1(1)
- week7晚作业
- Week7-1圆柱体表面积
- Week7-2POS tagging
- Week7-3HMM1
- Week7-4HMM2
- 现操-week7
- C程序设计进阶week7
- leetcode-month2-week7
- Minimum Path Sum
- 1047. 编程团体赛(20)
- LintCode 166-倒数第k个节点
- 十月工作总结:勿忘初心,继续前行
- 1046. 划拳(15)
- week7
- 【NOIP考前题目回顾】Luogu P1005
- Codeforces Round #349 (Div. 1) B. World Tour (暴力搜索)
- Verilog设计译码器、计数器
- extends、final
- mysql5.6多实例安装
- 关于递归的求水仙花数,网上搜索到的资料,储存起来,以便多次复习——初学者
- Ubuntu16.04 由于已经达到 MaxReports 限制,没有写入 apport 报告。
- SPOJ