题目原文:写程序交换一个整数二进制表示中的奇数位和偶数位,用尽可能少的代码实现。 (比如,第0位和第1位交换,第2位和第3位交换…)解答这道题目比较简单。分别将这个整数的奇数位和偶数位提取出来,然后移位取或即可。代码如下:int swap_bits(int x){ return ((x & 0...
分类:
其他好文 时间:
2015-04-22 22:01:00
阅读次数:
186
Binary numbers and their pattern of bits are always very interesting to computer programmers. In this problem you need to count the number of positive...
分类:
其他好文 时间:
2015-04-22 00:13:50
阅读次数:
287
题目:
Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 001110010...
分类:
其他好文 时间:
2015-04-21 11:11:36
阅读次数:
128
一:Leetcode 89 Gray Code
题目:The gray code is a binary numeral system where two successive values differ in only one bit.
Given a non-negative integer n representing the total number of bits in ...
分类:
其他好文 时间:
2015-04-20 17:10:42
阅读次数:
148
Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as00000010100101000001111010011100), return ...
分类:
其他好文 时间:
2015-04-20 11:01:21
阅读次数:
128
题目地址:https://leetcode.com/problems/bitwise-and-of-numbers-range/题目解析:参考https://leetcode.com/problems/number-of-1-bits/,我们知道n&n-1为n和n-1两者左边相同的部分,那么容易得到...
分类:
其他好文 时间:
2015-04-19 01:05:03
阅读次数:
316
题目描述Write a function that takes an unsigned integer and returns the number of ’1’ bits it has (also known as the Hamming weight).For example, the 32-bit integer ’11’ has binary representation 000000000...
分类:
其他好文 时间:
2015-04-18 22:02:38
阅读次数:
128
IOS使用SDWebImage出现下列类似警告的解决方案 CGBitmapContextCreate: unsupported parameter combination: 16 integer bits/component; 64 bits/pixel; 3-component color space; kCGImageAlphaPremultipliedF...
分类:
移动开发 时间:
2015-04-18 19:19:44
阅读次数:
146
Number of 1 Bits2015.4.17 05:48Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as theHamming wei...
分类:
其他好文 时间:
2015-04-17 07:10:13
阅读次数:
120
Reverse Bits2015.4.17 05:42Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as000000101001010...
分类:
其他好文 时间:
2015-04-17 07:09:09
阅读次数:
108