Android Byte Array to Short Convert toShort(byte[] data)

Here you can find the source of toShort(byte[] data)

Description

to Short

Declaration

public static short toShort(byte[] data) 

Method Source Code

//package com.java2s;

public class Main {
    public static short toShort(byte[] data) {
        return byteArrayToShort(data, 0);
    }//from ww  w.j  a va2  s  .co m

    private static short byteArrayToShort(byte[] b, int offset) {
        short value = 0;
        for (int i = 0; i < 2; i++) {
            int shift = (2 - 1 - i) * 8;
            value += (b[i + offset] & 0x000000FF) << shift;
        }
        return value;
    }
}

Related

  1. getShort(byte[] b, int index)
  2. getShort(byte[] buf, boolean bigEndian)
  3. getShort(byte[] buf, int pos, boolean bigEndian)
  4. getShort(byte[] bytes)
  5. toShort(byte[] b, int pos)
  6. toShort(byte[] data)
  7. makeShort(byte b1, byte b0)
  8. bytes2short(byte[] data)
  9. ByteToString(byte[] byteArray)