Java Byte Array to Short bytes2short(byte[] bytes, int offset, boolean bigEndian)

Here you can find the source of bytes2short(byte[] bytes, int offset, boolean bigEndian)

Description

bytesshort

License

Apache License

Declaration

public static short bytes2short(byte[] bytes, int offset, boolean bigEndian) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static short bytes2short(byte[] bytes, int offset, boolean bigEndian) {
        short val = 0;

        if (bigEndian) {
            val += (bytes[offset + 0] & 0xff) << 8;
            val += (bytes[offset + 1] & 0xff);
        } else {// ww w  . ja  v  a 2  s.  c  o m
            val += (bytes[offset + 1] & 0xff) << 8;
            val += (bytes[offset + 0] & 0xff);
        }

        return val;
    }

    public static short bytes2short(byte[] bytes, boolean bigEndian) {
        return bytes2short(bytes, 0, bigEndian);
    }
}

Related

  1. byte2short(byte[] data)
  2. byte2short(byte[] value, int offset)
  3. byte2Short(int loc, byte b[])
  4. bytes2short(byte[] b)
  5. bytes2Short(byte[] bytes)
  6. bytes2Short(byte[] input)
  7. bytes2short(byte[] src)
  8. bytesToShort(byte A, byte B)
  9. bytesToShort(byte a, byte b, boolean swapBytes)