Java Byte Array to Int bytesToInt16(byte highByte, byte lowByte)

Here you can find the source of bytesToInt16(byte highByte, byte lowByte)

Description

Converts 2 bytes to a signed integer sample with 16bit range.

License

Open Source License

Declaration

public static int bytesToInt16(byte highByte, byte lowByte) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*  w ww  .ja  v  a  2s .c om*/
     * Converts 2 bytes to a signed integer sample with 16bit range.
     * <p> This is a reference function.
     */
    public static int bytesToInt16(byte highByte, byte lowByte) {
        return (highByte << 8) | (lowByte & 0xFF);
    }

    /**
     * Converts 2 successive bytes starting at <code>byteOffset</code> in
     * <code>buffer</code> to a signed integer sample with 16bit range.
     * <p>
     * For little endian, buffer[byteOffset] is interpreted as low byte,
     * whereas it is interpreted as high byte in big endian.
     * <p> This is a reference function.
     */
    public static int bytesToInt16(byte[] buffer, int byteOffset,
            boolean bigEndian) {
        return bigEndian ? ((buffer[byteOffset] << 8) | (buffer[byteOffset + 1] & 0xFF))
                : ((buffer[byteOffset + 1] << 8) | (buffer[byteOffset] & 0xFF));
    }
}

Related

  1. bytesToInt(final byte[] buf, final int offset)
  2. bytesToInt(final byte[] bytes)
  3. bytesToInt(final byte[] bytes)
  4. bytesToInt(final byte[] bytes, final int position, final int length, final int bitShiftStart, final int bitShitIncrement)
  5. bytesToInt(int off, byte... arr)
  6. bytesToInt2(byte[] arr, int offset)
  7. bytesToIntArr(byte[] arr, int offset, int[] num, int soff, int size)
  8. bytesToInteger(byte[] b)
  9. bytesToInteger(byte[] b, int off)