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

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

Description

a & b

License

Open Source License

Parameter

Parameter Description
a a parameter
b a parameter

Declaration

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

Method Source Code

//package com.java2s;
/**/*from  w ww .jav  a 2s.co  m*/
 * ?????????? unsigned ????????????????????????????????????????
 *
 * License : MIT License
 */

public class Main {
    /**
     * a & b
     * @param a
     * @param b
     * @return
     */
    public static byte[] and(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. 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)