我用a java.util.BitSet来存储密集的位向量.
我想实现一个将位向右移1的操作,类似于>>>on int.
有一个库函数可以改变BitSets吗?
如果没有,是否有比下面更好的方法?
public static void logicalRightShift(BitSet bs) {
for (int i = 0; (i = bs.nextSetBit(i)) >= 0;) {
// i is the first bit in a run of set bits.
// Set any bit to the left of the run.
if (i != 0) { bs.set(i - 1); }
// Now i is the index of the bit after the end of the run.
i = bs.nextClearBit(i); // nextClearBit never …Run Code Online (Sandbox Code Playgroud)