Java Byte Array Compare memcmp(final byte[] first, final int firstStart, final byte[] second, final int secondStart, int size)

Here you can find the source of memcmp(final byte[] first, final int firstStart, final byte[] second, final int secondStart, int size)

Description

memcmp

License

Open Source License

Declaration

public static int memcmp(final byte[] first, final int firstStart, final byte[] second, final int secondStart,
            int size) 

Method Source Code

//package com.java2s;
/*/*from ww  w  .  j  a  va 2  s .co  m*/
 * Copyright (c) 2014, 2018 Oracle and/or its affiliates. All rights reserved. This
 * code is released under a tri EPL/GPL/LGPL license. You can use it,
 * redistribute it and/or modify it under the terms of the:
 *
 * Eclipse Public License version 1.0, or
 * GNU General Public License version 2, or
 * GNU Lesser General Public License version 2.1.
 */

public class Main {
    public static int memcmp(final byte[] first, final int firstStart, final byte[] second, final int secondStart,
            int size) {
        assert firstStart + size <= first.length;
        assert secondStart + size <= second.length;

        int cmp;

        for (int i = 0; i < size; i++) {
            if ((cmp = (first[firstStart + i] & 0xff) - (second[secondStart + i] & 0xff)) != 0) {
                return cmp;
            }
        }

        return 0;
    }
}

Related

  1. memcmp(byte[] a, int a_offset, byte[] b, int b_offset, int length)
  2. memcmp(byte[] a, int aoff, int alen, byte[] b, int boff, int blen)
  3. memcmp(byte[] bytes, byte[] bytes2, int nbElem)
  4. memcmp(byte[] s1, int s1Size, int s1offset, byte[] s2, int s2Size, int s2offset)
  5. memcmp(final byte[] a, final byte[] b, int length)
  6. memcmp(List header, String string, int size)