Java - 使用按位运算的循环移位 [英] Java - Circular shift using bitwise operations
本文介绍了Java - 使用按位运算的循环移位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何用 int
位代表的位串实现 循环右移 。
I am wondering how to implement a circular right shift by k of the bitstring represented by the int
bits.
public int rtCircShift(int bits, int k)
{
return bits >> k;
}
所有这些代码都是返回0 ,如何我可以进行循环转换吗?
All this code does is return 0, how can I make it a circular shift?
推荐答案
这应该有效:
return (bits >>> k) | (bits << (Integer.SIZE - k));
另见维基百科关于轮班的文章。
这篇关于Java - 使用按位运算的循环移位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文