Java Utililty Methods xor

List of utility methods to do xor

Description

The list of methods to do xor are organized into topic(s).

Method

booleanxor(boolean a, boolean b)
Perform an either/or operator
return (a && !b) || (b && !a);
boolean[]xor(boolean a[], boolean b[])
Computes vector whose elements are the results of logical XOR of the respective elements in the two given vectors.
boolean[] c = new boolean[a.length];
for (int i = 0; i < c.length; i++) {
    c[i] = a[i] ^ b[i];
return c;
booleanxor(boolean b1, boolean b2)
Concatenate two booleans with the operation "XOR"
return (b1 != b2);
booleanxor(boolean b1, boolean b2)
xor
if (b1 == false && b2 == false) {
    return false;
} else if (b1 == false && b2 == true) {
    return true;
} else if (b1 == true && b2 == false) {
    return true;
} else {
    return false;
...
booleanxor(boolean o, boolean t)
xor
return !xnor(o, t);
booleanxor(boolean val1, boolean val2)
Returns (val1 != val2).
return (val1 != val2);
booleanxOr(boolean x, boolean y)
x Or
return ((x || y) && !(x && y));
booleanxor(boolean... bools)
An xor gate
boolean didOr = false;
boolean total = false;
for (boolean bool : bools) {
    if (total && bool) {
        if (didOr)
            return false;
    } else {
        total = total || bool;
...
booleanxor(boolean[] array)

Performs an xor on a set of booleans.

 BooleanUtils.xor(new boolean[] { true, true })   = false BooleanUtils.xor(new boolean[] { false, false }) = false BooleanUtils.xor(new boolean[] { true, false })  = true 
if (array == null) {
    throw new IllegalArgumentException("The Array must not be null");
} else if (array.length == 0) {
    throw new IllegalArgumentException("Array is empty");
int trueCount = 0;
for (int i = 0; i < array.length; i++) {
    if (array[i]) {
...
boolean[][]xor(boolean[][] b1, boolean[][] b2)
xor
boolean[][] temp = new boolean[b1.length][b1[0].length];
for (int i = 0; i < b1.length; i++) {
    for (int j = 0; j < b1[0].length; j++) {
        temp[i][j] = b1[i][j] ^ b2[i][j];
return temp;