Java xor XOR(byte[] array1, byte[] array2)

Here you can find the source of XOR(byte[] array1, byte[] array2)

Description

XOR two byte arrays The following method is used to XOR two byte array objects

License

Open Source License

Parameter

Parameter Description
array1 A byte array
array2 A byte array

Return

byte[] The result of array1^array2

Declaration

public static byte[] XOR(byte[] array1, byte[] array2) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//  w  w w . ja  va 2s.  c  o  m
     * XOR two byte arrays
     * 
     * The following method is used to XOR two byte array objects
     * 
     * @param array1
     *            A byte array
     * @param array2
     *            A byte array
        
     * @return byte[] The result of array1^array2 */
    public static byte[] XOR(byte[] array1, byte[] array2) {
        byte[] result = new byte[array1.length];
        for (int i = 0; i < array1.length; i++) {
            result[i] = (byte) (array1[i] ^ array2[i]);
        }
        return result;
    }
}

Related

  1. xor(byte[] a, byte[] b)
  2. xor(byte[] a, byte[] b)
  3. xor(byte[] a, int offsetA, byte[] b, int offsetB, byte[] dst, int dstOffset, int length)
  4. xor(byte[] aBuffer, int aOffset, int aLength, byte[] aMask, int aMaskOffset)
  5. xor(byte[] array1, byte[] array2)
  6. xor(byte[] b1, byte[] b2)
  7. xor(byte[] b1, byte[] b2)
  8. xor(byte[] block, byte[] val)
  9. xor(byte[] block, byte[] val)