Java Byte Array to Int bytes2int(byte value1, byte value2)

Here you can find the source of bytes2int(byte value1, byte value2)

Description

Example, hex code: 05 01

License

Open Source License

Parameter

Parameter Description
value1 here 05
value2 here 01

Return

01 * 256 + 05

Declaration

public static int bytes2int(byte value1, byte value2) 

Method Source Code

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

public class Main {
    /**// w  w w  . j a  v a2s . c  o m
     * Example, hex code: 05 01
     * @param value1 here 05
     * @param value2 here 01
     * @return 01 * 256 + 05
     */
    public static int bytes2int(byte value1, byte value2) {
        return (byte2int(value1) + byte2int(value2) * 256);
    }

    /**
     * Example, hex code: 05 03 00 01
     * @param value1 here 05
     * @param value2 here 03
     * @param value3 here 00
     * @param value4 here 01
     * @return (03 * 256 + 05) + (01 * 256 + 00) * 65536
     */
    public static int bytes2int(byte value1, byte value2, byte value3, byte value4) {
        return (bytes2int(value1, value2) + bytes2int(value3, value4) * 65536);
    }

    public static int byte2int(byte value) {
        if (value < 0) {
            return (int) (256 + value);
        } else {
            return (int) value;
        }
    }
}

Related

  1. byte2int(final byte[] arr)
  2. byte2int(int[] output, byte[] input, int ioff, int len)
  3. byte2int2(byte[] src, int height, int width)
  4. byte2intarr(byte[] in)
  5. byte2intArray(byte[] b)
  6. bytes2Int(byte... bytes)
  7. bytes2int(byte[] ary)
  8. bytes2int(byte[] b)
  9. bytes2Int(byte[] b, int start, int len)