Write a program to swap odd and even bits in an integer with as few instructions as possible.
public static int swapOddEvenBits(int x)
{
return ( (( x & 0xaaaaaaaa) >> 1 | (x & 0x55555555) << 1) );...
分类:
编程语言 时间:
2015-03-14 16:57:40
阅读次数:
154
Reverse Bits问题:Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as000000101001010000011110100...
分类:
其他好文 时间:
2015-03-14 16:42:44
阅读次数:
114
LeetCode 191 Number of 1 Bits解法一(较为传统都解法):使用将n不断右移,并与1想&得到1的个数;(也有使用除法/2的,明显除法的运行效率要低于位移)时间复杂度:0(logn) 1 int hammingWeight(uint32_t n){ 2 int coun...
分类:
其他好文 时间:
2015-03-14 12:16:16
阅读次数:
138
Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return...
分类:
其他好文 时间:
2015-03-14 07:24:14
阅读次数:
139
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 i...
分类:
其他好文 时间:
2015-03-14 06:14:08
阅读次数:
165
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-03-14 06:13:47
阅读次数:
147
题目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 0000000000...
分类:
其他好文 时间:
2015-03-13 16:35:33
阅读次数:
125
题目:Reverse BitsReverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010...
分类:
其他好文 时间:
2015-03-12 14:57:14
阅读次数:
125
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 00000000...
分类:
其他好文 时间:
2015-03-12 11:34:16
阅读次数:
112
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-03-12 11:29:01
阅读次数:
120