日期:2014-05-20  浏览次数:20800 次

bitset移位
在java里,Bitset类左/右移位怎么实现?

------解决方案--------------------
哥们儿.没办法了.只能自己写相应的moveRigth(),moveLife()方法了.

我写了一个.
供朋友们讨论:
import java.util.BitSet;

public class Test extends BitSet{
private static final long serialVersionUID = 1L;

public static BitSet moveLeft(BitSet bs,int count) {
if(bs == null || bs.isEmpty()) {
return bs;
}
BitSet b = bs.get(count, bs.size());
return b;

}

public static BitSet moveRigth(BitSet bs,int count) {
if(bs == null || bs.isEmpty()) {
return bs;
}
BitSet b = new BitSet();

int bsSize = bs.size() - count;

for (int i = 0; i < bsSize; i++) {
b.set(count++ , bs.get(i));
}
return b;
}
/**
* @param args
*/
public static void main(String[] args) {
BitSet b = new BitSet();
b.set(0,10, true);

BitSet bs = moveLeft(b,3);

for (int i = 0; i < 64; i++) {
if (i<10) {
System.out.println("0"+i+"=="+bs.get(i));
} else {
System.out.println(i+"=="+bs.get(i));
}
}

BitSet b1 = new BitSet();
b1.set(0,10, true);

BitSet bs1 = moveRigth(b,3);
System.out.println("\n");
for (int i = 0; i < 64; i++) {
if (i<10) {
System.out.println("0"+i+"=="+bs1.get(i));
} else {
System.out.println(i+"=="+bs1.get(i));
}
}
}
}