The xor() method in the BitSet class is used to perform XOR with this bit set (invoking) and the bit set argument. The result of logical this.bitset bit set.
XOR is a two digital input circuit that results in
1when both input values differ.
This is used to perform logical XOR between two BitSet objects:
void xor(BitSet set)
set: The argument value of BitSet type.
This method has no return type. It is defined as void in the built-in BitSet class.
As highlighted below, we have two BitSet objects, bitset1 and bitset2, with at least 8 random values, each using the java.util.Random class. As a result, we are doing logical XOR between bitset1 and bitset2 in line 21.
import java.util.BitSet;// Random Class for random number generatorimport java.util.Random;class EdPresso {public static void main( String args[] ) {// object for Random ClassRandom rand = new Random();// objects of BitSet ClassBitSet bitset1 = new BitSet(10);BitSet bitset2 = new BitSet(10);// set some bitsfor(int i = 0; i < 8; i++) {bitset1.set(rand.nextInt(20));bitset2.set(rand.nextInt(20));}System.out.println("bitset1: ");System.out.println(bitset1);System.out.println("\nbitset2: ");System.out.println(bitset2);// XOR operation on bitsbitset1.xor(bitset2);System.out.println("\nbitset1 OR bitset2: ");System.out.println(bitset1);}}