Java xor xor(char[] a, char[] b)

Here you can find the source of xor(char[] a, char[] b)

Description

xor

License

Open Source License

Return

xor of arrays a and b

Declaration

public static char[] xor(char[] a, char[] b) 

Method Source Code

//package com.java2s;
/**//from ww w . j  ava 2s . com
 * WebSYNC Client Copyright 2007, 2008 Dataview Ltd
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software 
 * Foundation, either version 3 of the License, or (at your option) any later 
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT 
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 * 
 * A copy of the GNU General Public License version 3 is included with this 
 * source distribution. Alternatively this licence can be viewed at 
 * <http://www.gnu.org/licenses/>
 */

public class Main {
    /**
     * @return xor of arrays a and b
     */
    public static char[] xor(char[] a, char[] b) {
        int length = Math.min(a.length, b.length);
        char[] result = new char[length];
        for (int i = 0; i < length; i++) {
            // ^ is the xor operator
            // see http://mindprod.com/jgloss/xor.html
            result[i] = (char) (a[i] ^ b[i]);
        }
        return result;
    }
}

Related

  1. xor(byte[] firstBytes, int firstOffset, byte[] secondBytes, int secondOffset, byte[] outBytes, int outOffset, int size)
  2. xor(byte[] op1, byte[] op2)
  3. xor(byte[] source, byte[] key)
  4. xor(byte[] x, byte[] y)
  5. xor(byte[]... bytesArr)
  6. xor(double lhs, double rhs)
  7. xor(final boolean value1, final boolean value2)
  8. xor(final boolean x, final boolean y)
  9. xor(final byte[] bytesA, final byte[] bytesB)