Java xor xor(byte[] a, int offsetA, byte[] b, int offsetB, byte[] dst, int dstOffset, int length)

Here you can find the source of xor(byte[] a, int offsetA, byte[] b, int offsetB, byte[] dst, int dstOffset, int length)

Description

XOR length number of bytes from a with b using the syntax ( a[i] ^ b[i] ) and store the result in dst

License

Open Source License

Parameter

Parameter Description
a the first array
offsetA the offset into the a array at which to start XORing values
b the second array
offsetB the offset into the b array at which to start XORing values
dst the destination array to store the XORed results in
dstOffset the offset into the dst array at which to start storing the XORed values
length the number of values to read from a and b and store in dst

Declaration

public static final void xor(byte[] a, int offsetA, byte[] b, int offsetB, byte[] dst, int dstOffset,
        int length) 

Method Source Code

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

public class Main {
    /**//from   ww  w .j av a 2  s.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[] 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[] aBuffer, int aOffset, int aLength, byte[] aMask, int aMaskOffset)
  7. XOR(byte[] array1, byte[] array2)
  8. xor(byte[] array1, byte[] array2)
  9. xor(byte[] b1, byte[] b2)