List of usage examples for java.util BitSet set
public void set(int bitIndex)
From source file:Main.java
public static void main(String[] args) { BitSet bitset1 = new BitSet(8); BitSet bitset2 = new BitSet(8); // assign values to bitset1 bitset1.set(0); bitset1.set(1);/*from www . j av a2s. c om*/ bitset1.set(2); // assign values to bitset2 bitset2.set(2); bitset2.set(4); // print the sets System.out.println("Bitset1:" + bitset1); System.out.println("Bitset2:" + bitset2); // print the length of each bitset System.out.println(bitset1.length()); System.out.println(bitset2.length()); }
From source file:Main.java
public static void main(String[] args) { BitSet bitset1 = new BitSet(8); BitSet bitset2 = new BitSet(8); // assign values to bitset1 bitset1.set(0); bitset1.set(1);/*from w ww. j a v a 2 s.c o m*/ // assign values to bitset2 bitset2.set(2); bitset2.set(4); bitset2.set(6); // print the sets System.out.println("Bitset1:" + bitset1); System.out.println("Bitset2:" + bitset2); // perform a logical or between the two bitsets bitset1.or(bitset2); System.out.println(bitset1); }
From source file:Main.java
public static void main(String[] args) { BitSet bitset1 = new BitSet(8); BitSet bitset2 = new BitSet(8); // assign values to bitset1 bitset1.set(0); bitset1.set(1);/*from w w w.j ava 2s . c o m*/ // assign values to bitset2 bitset2.set(2); bitset2.set(4); // print the sets System.out.println("Bitset1:" + bitset1); System.out.println("Bitset2:" + bitset2); // print the first set bit of bitset1 System.out.println(bitset1.nextSetBit(0)); // print the first set bit of bitset2 after index 5 System.out.println(bitset2.nextSetBit(5)); }
From source file:TwoBitPlanets.java
public static void main(String args[]) { String names[] = { "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto" }; int moons[] = { 0, 0, 1, 2, 16, 18, 17, 8, 1 }; int namesLen = names.length; BitSet bits = new BitSet(namesLen); for (int i = 0; i < namesLen; i++) { if ((moons[i] % 2) == 0) { bits.set(i); }/*from w w w. ja va 2 s . c o m*/ } for (int i = 0; i < namesLen; i++) { System.out.println(names[i] + " Even # Moons (" + moons[i] + ")? " + bits.get(i)); } }
From source file:Main.java
public static void main(String[] args) { BitSet bitset1 = new BitSet(8); BitSet bitset2 = new BitSet(8); // assign values to bitset1 bitset1.set(0); bitset1.set(1);/*from w w w. j a va 2s .c om*/ bitset1.set(2); // assign values to bitset2 bitset2.set(2); bitset2.set(4); // print the sets System.out.println("Bitset1:" + bitset1); System.out.println("Bitset2:" + bitset2); // return a hashcode for each bitset System.out.println(bitset1.hashCode()); System.out.println(bitset2.hashCode()); }
From source file:Main.java
public static void main(String[] args) { BitSet bitset1 = new BitSet(8); BitSet bitset2 = new BitSet(8); // assign values to bitset1 bitset1.set(0); bitset1.set(1);/* w w w.j av a 2s. c o m*/ bitset1.set(2); // assign values to bitset2 bitset2.set(2); bitset2.set(4); bitset2.set(6); // print the sets System.out.println("Bitset1:" + bitset1); System.out.println("Bitset2:" + bitset2); // perform a xor operation between two bitsets bitset1.xor(bitset2); System.out.println(bitset1); }
From source file:Main.java
public static void main(String[] args) { BitSet bitset1 = new BitSet(8); BitSet bitset2 = new BitSet(8); // assign values to bitset1 bitset1.set(0); bitset1.set(1);//from www.java2s .c om bitset1.set(2); // assign values to bitset2 bitset2.set(2); bitset2.set(4); bitset2.set(6); // print the sets System.out.println("Bitset1:" + bitset1); System.out.println("Bitset2:" + bitset2); // print the string representations of the bitsets System.out.println(bitset1.toString()); System.out.println(bitset2.toString()); }
From source file:Main.java
public static void main(String[] args) { BitSet bitset1 = new BitSet(8); BitSet bitset2 = new BitSet(8); // assign values to bitset1 bitset1.set(0); bitset1.set(1);/*from w ww . jav a2s . c o m*/ bitset1.set(2); // assign values to bitset2 bitset2.set(2); bitset2.set(4); // print the sets System.out.println("Bitset1:" + bitset1); System.out.println("Bitset2:" + bitset2); // get index 1 to 4 of bitset1 System.out.println(bitset1.get(1, 4)); // get index 2 to 10 of bitset2 System.out.println(bitset2.get(2, 10)); }
From source file:Main.java
public static void main(String[] args) { BitSet bitset1 = new BitSet(8); BitSet bitset2 = new BitSet(8); // assign values to bitset1 bitset1.set(0); bitset1.set(1);// w w w. ja v a 2s .co m bitset1.set(2); // assign values to bitset2 bitset2.set(2); bitset2.set(4); // print the sets System.out.println("Bitset1:" + bitset1); System.out.println("Bitset2:" + bitset2); // print the first clear bit of bitset1 System.out.println(bitset1.nextClearBit(0)); // print the first clear bit of bitset2 after index 5 System.out.println(bitset2.nextClearBit(5)); }
From source file:Main.java
public static void main(String[] args) { BitSet bitset1 = new BitSet(8); BitSet bitset2 = new BitSet(8); // assign values to bitset1 bitset1.set(0); bitset1.set(1);//from w w w. jav a2 s . c o m bitset1.set(2); // assign values to bitset2 bitset2.set(2); bitset2.set(4); // print the sets System.out.println("Bitset1:" + bitset1); System.out.println("Bitset2:" + bitset2); // print cardinality for bitset1 System.out.println(bitset1.cardinality()); // print cardinality for bitset2 System.out.println(bitset2.cardinality()); }