62,628
社区成员
发帖
与我相关
我的任务
分享
能否详细解释一下。。。。
谢谢[/quote]
比如0101这个 i = (i & 0x55555555) << 1 | (i >>> 1) & 0x55555555;
这是交换2位的 拆解成 (i & 0x5) << 1 | (i >>> 1) & 0x5;
这样你看清楚一点 完成的是2位的交换
[/quote]
效果上是这样的,但是我还是没有想明白这原理到底是什么?
感觉有点抽象?
求解释,表示我还没有看出二分法。。。。
我只是感觉有点抽象,通过那样的位运算就倒转过来了,实在没有看明白,能不能说一下数学原理
谢谢!
或者有什么样的资料可以看看?
谢谢
能否详细解释一下。。。。
谢谢[/quote]
比如0101这个 i = (i & 0x55555555) << 1 | (i >>> 1) & 0x55555555;
这是交换2位的 拆解成 (i & 0x5) << 1 | (i >>> 1) & 0x5;
这样你看清楚一点 完成的是2位的交换
能否详细解释一下。。。。
谢谢/**
* Returns the value obtained by reversing the order of the bits in the
* two's complement binary representation of the specified <tt>int</tt>
* value.
*
* @return the value obtained by reversing order of the bits in the
* specified <tt>int</tt> value.
* @since 1.5
*/
public static int reverse(int i) {
// HD, Figure 7-1
i = (i & 0x55555555) << 1 | (i >>> 1) & 0x55555555;
i = (i & 0x33333333) << 2 | (i >>> 2) & 0x33333333;
i = (i & 0x0f0f0f0f) << 4 | (i >>> 4) & 0x0f0f0f0f;
i = (i << 24) | ((i & 0xff00) << 8) |
((i >>> 8) & 0xff00) | (i >>> 24);
return i;
}
jdk里面的分治法
01010101
00110011
00001111
这就是 3 5 F
能看明白吗?