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

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

Description

a ^ b

License

Open Source License

Parameter

Parameter Description
a a parameter
b a parameter

Declaration

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

Method Source Code

//package com.java2s;
/**// w  ww  .j a  v  a2s .c o m
 * ?????????? unsigned ????????????????????????????????????????
 *
 * License : MIT License
 */

public class Main {
    /**
     * a ^ b
     * @param a
     * @param b
     * @return
     */
    public static byte[] xor(byte[] a, byte[] b) {
        if (a == null)
            throw new IllegalArgumentException("a should not be null");
        if (b == null)
            throw new IllegalArgumentException("b should not be null");
        if (a.length != b.length)
            throw new IllegalArgumentException(
                    "byte array length should be same");

        int len = a.length;
        byte[] result = new byte[len];
        for (int i = 0; i < len; i++) {
            result[i] = (byte) ((a[i] ^ b[i]) & 0x000000ff);
        }

        return result;
    }
}

Related

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