Here you can find the source of toShort(byte[] b)
public static short toShort(byte[] b)
//package com.java2s; public class Main { public static short toShort(byte[] b) { short value = 0; for (int x = 0; x < b.length; x++) { value |= b[x] & 0xFF;// ww w . j a v a2 s . c om // if it's the last one, don't shift if (x != b.length - 1) { value <<= 8; } } return value; } }