Java Byte Array And and(byte[] a, byte[] b)

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

Description

and

License

Open Source License

Return

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

Declaration

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

Method Source Code

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

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

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

    /** AND {@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 ANDing values
     * @param b the second array
     * @param offsetB the offset into the {@code b} array at which to start ANDing values
     * @param dst the destination array to store the ANDed results in
     * @param dstOffset the offset into the {@code dst} array at which to start storing the ANDed values
     * @param length the number of values to read from {@code a} and {@code b} and store in {@code dst}
     */
    public static final void and(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. and(byte[] a, byte[] b)
  2. and(byte[] a, byte[] b)
  3. and(byte[] a, int offsetA, byte[] b, int offsetB, byte[] dst, int dstOffset, int length)
  4. and(byte[] data1, byte[] data2)