Java Bits Convert to bitWiseAnd(final byte[] array1, final byte[] array2)

Here you can find the source of bitWiseAnd(final byte[] array1, final byte[] array2)

Description

Combine two arrays by doing the logic And byte by byte.

License

Open Source License

Declaration

public static void bitWiseAnd(final byte[] array1, final byte[] array2) 

Method Source Code

//package com.java2s;
/**//  ww  w  .jav  a  2 s .c  o m
 * ****************************************************************************
 * Copyright (c) 2015, MasterCard International Incorporated and/or its
 * affiliates. All rights reserved.
 * <p/>
 * The contents of this file may only be used subject to the MasterCard
 * Mobile Payment SDK for MCBP and/or MasterCard Mobile MPP UI SDK
 * Materials License.
 * <p/>
 * Please refer to the file LICENSE.TXT for full details.
 * <p/>
 * TO THE EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS", WITHOUT
 * WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NON INFRINGEMENT. TO THE EXTENT PERMITTED BY LAW, IN NO EVENT SHALL
 * MASTERCARD OR ITS AFFILIATES BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 * *****************************************************************************
 */

public class Main {
    /**
     * Combine two arrays by doing the logic And byte by byte. The first vector is modified
     * The two input arrays must have the same length
     * */
    public static void bitWiseAnd(final byte[] array1, final byte[] array2) {
        if (array1 == null || array2 == null) {
            throw new IllegalArgumentException("Input data cannot be null");
        }
        if (array1.length != array2.length) {
            throw new IllegalArgumentException(
                    "Arrays must have the same length");
        }
        for (int i = 0; i < array1.length; i++) {
            array1[i] &= array2[i];
        }
    }
}

Related

  1. bitToBoolean(byte b)
  2. bitToBoolean(final byte value, final int bitNbr)
  3. bitToLong(byte[] bytes, int offset, int length)
  4. bitToLong(byte[] bytes, int offset, int length)
  5. bitValueHelper(final int index, final int[] data)