相关疑难解决方法(0)

转移Java BitSet

我用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)

java bit-shift bitset

20
推荐指数
4
解决办法
9058
查看次数

标签 统计

bit-shift ×1

bitset ×1

java ×1