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

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

Description

xor

License

Open Source License

Return

a newly created array containing the XORed results of a and b

Declaration

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

Method Source Code

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

public class Main {
    /**/*from   w ww . ja  v  a 2s .co  m*/
     * @return a newly created array containing the XORed results of {@code a} and {@code b}
     * @see ArrayUtil#xor(byte[], int, byte[], int, byte[], int, int) xor()
     */
    public static final byte[] xor(byte[] a, byte[] b) {
        byte[] dst = new byte[a.length];
        xor(a, 0, b, 0, dst, 0, dst.length);
        return dst;
    }

    /**
     * @see ArrayUtil#xor(byte[], int, byte[], int, byte[], int, int) xor()
     */
    public static final void xor(byte[] a, byte[] b, byte[] dst, int length) {
        xor(a, 0, b, 0, dst, 0, length);
    }

    /** XOR {@code length} number of bytes from {@code a} with {@code b} using the syntax ({@code a[i] ^ b[i]})
     * and store the result in {@code dst}
     * @param a the first array
     * @param offsetA the offset into the {@code a} array at which to start XORing values
     * @param b the second array
     * @param offsetB the offset into the {@code b} array at which to start XORing values
     * @param dst the destination array to store the XORed results in
     * @param dstOffset the offset into the {@code dst} array at which to start storing the XORed values
     * @param length the number of values to read from {@code a} and {@code b} and store in {@code dst}
     */
    public static final void xor(byte[] a, int offsetA, byte[] b, int offsetB, byte[] dst, int dstOffset,
            int length) {
        for (int i = 0, aI = offsetA, bI = offsetB, dstI = dstOffset; i < length; i++, aI++, bI++, dstI++) {
            dst[dstI] = (byte) (a[aI] ^ b[bI]);
        }
    }
}

Related

  1. xor(byte abyte0[])
  2. xor(byte data[], byte key[])
  3. xor(byte lhs[], byte rhs[])
  4. xor(byte[] a, byte[] b)
  5. xor(byte[] a, byte[] b)
  6. xor(byte[] a, byte[] b)
  7. xor(byte[] a, byte[] b)
  8. xor(byte[] a, byte[] b)
  9. xor(byte[] a, int offsetA, byte[] b, int offsetB, byte[] dst, int dstOffset, int length)