| |
9. 47. 5. Set value to BitSet and then do AND, OR and XOR actions |
|
import java.util.BitSet;
class BitSetDemo {
public static void main(String args[]) {
BitSet bits1 = new BitSet(16);
BitSet bits2 = new BitSet(16);
for (int i = 0; i < 16; i++) {
if ((i % 2) == 0)
bits1.set(i);
if ((i % 5) != 0)
bits2.set(i);
}
System.out.println("Initial pattern in bits1: ");
System.out.println(bits1);
System.out.println("\nInitial pattern in bits2: ");
System.out.println(bits2);
// AND bits
bits2.and(bits1);
System.out.println("\nbits2 AND bits1: ");
System.out.println(bits2);
// OR bits
bits2.or(bits1);
System.out.println("\nbits2 OR bits1: ");
System.out.println(bits2);
// XOR bits
bits2.xor(bits1);
System.out.println("\nbits2 XOR bits1: ");
System.out.println(bits2);
}
}
|
|
9. 47. 位集合 | | 9. 47. 1. | 位设置操作 | | | | 9. 47. 2. | 操作集位 | | | | 9. 47. 3. | 确定集大小 | | | | 9. 47. 4. | 克隆位集 | | | | 9. 47. 5. | Set value to BitSet and then do AND, OR and XOR actions | | | | 9. 47. 6. | 使用位集合 | | |
|